by anc2020 · 15y ago · 0 comments
This should work okay:
for (var i = 0; i < 5; i++) {
$(DOMelement:eq(i)).click((function(i) {
return function() {
console.info(i);
}
}(i)));
}
Also surely DOMelement.eq(i) as opposed to DOMelement:eq(i)?Also, this feels like piling on, but I think the original (intentionally erroneous) example would print '5' repeatedly rather than '4'. var i ends up with the value 5.
for DOM part, I didn't understand your question. However, the right way to do it is
$(DOMelement:eq(i)).each();
to iterate through each element.