How to get the children of the $(this) selector?

前端 未结 18 2185
日久生厌
日久生厌 2020-11-22 05:10

I have a layout similar to this:

and would like to use a jQuery selector to selec

18条回答
  •  囚心锁ツ
    2020-11-22 05:28

    The jQuery constructor accepts a 2nd parameter called context which can be used to override the context of the selection.

    jQuery("img", this);
    

    Which is the same as using .find() like this:

    jQuery(this).find("img");
    

    If the imgs you desire are only direct descendants of the clicked element, you can also use .children():

    jQuery(this).children("img");
    

提交回复
热议问题