I am working on a code, perhaps my approach is wrong working inside a “for” loop. Here is it:
for(var index = 0; index < $('div.parent').find('div.child').length; index++){
var element[index] = $('div.parent').find('div.child').eq(index);
// some code
}
The code should look like this:
for(var index = 0; index < $('div.parent').find('div.child').length; index++){
var element1 = $('div.parent').find('div.child').eq(1);
// some code with element1
var element2 = $('div.parent').find('div.child').eq(2);
// some code with element2
}
Thanks for any suggestion.
You can’t dynamically create a variable of a certain name. You will need to use an array:
Or even simpler with jQuery: