Targeting $(this) within nested for each loops in jQuery
html, javascript, jquery
Solution
$('li').each(function(){
var $this = $(this);
$this.children("li").each(function(){
$this; // parent li
this; // child li
});
});
Problem
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: ``` $('li').each(function(){ // I believe $(this) would target each li item... $(this).children("li").each(function(){ // ... but how can I target each of these li items? Doesn't $(this) target the original loop? }); }); ```