jquery loop holding last value
I have divs with numbered ids that i want to do some processing with the
click event:
$(function() {
for (var i = 1; i != 10; ++i) {
$("#div" + i).live('click', function () {
//...
console.log(i); // always prints 10
});
}
});
// html
<div id="div1">...</div>
<div id="div2">...</div>
etc.
I was expecting that a click event on each div will fire its own event
handler. But that is not the case.
Any fix please.
No comments:
Post a Comment