Targeting $(this) within nested for each loops in jQuery

后端 未结 5 1637
执念已碎
执念已碎 2020-12-02 12:29

I\'m trying to figure out, when iterating through some list items, how to target each \"$(this)\" equivalent within nested foreach loops. Here is an example of my problem:

5条回答
  •  一整个雨季
    2020-12-02 12:43

    Nope, this refers to each of the child

  • items. Try it out.

    Most (if not all) DOM-interacting jQuery callbacks set this to to the DOM element that you're working with.

    You could also write:

    $('li').children("li").each(function(){
        var $this = $(this);
    });
    

提交回复
热议问题