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

后端 未结 5 1635
执念已碎
执念已碎 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:46

    Don't use this! Use function parameters!

    $('li').each(function(i, li){
        $(li).children("li").each(function(ii, li2){
            $(li)...
            $(li2)...
        });
    });
    

    This is more in keeping with the native JavaScript iterators.

    ...though an

  • can't be the direct child of another
提交回复
热议问题