Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  175] [ 1]  / answers: 1 / hits: 61571  / 11 Years ago, thu, may 2, 2013, 12:00:00

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?
});
});

More From » jquery

 Answers
12
$('li').each(function(){
var $this = $(this);
$this.children(li).each(function(){
$this; // parent li
this; // child li
});
});

[#78466] Wednesday, May 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 4 Years ago
;