i have the following code :
$(document).ready(function () {
for (i = 1; i <= number_of_banners; i++) {
var selector = "#link_" + i;
$(selector).click(function () {
alert(i);
});
}
});
but the alert() can't get the "i" variable from the for loop. How can I use the i variable of for loop inside the .click function ?
.click()
handlers are using thei
variable from the for loop - but all of them are referencing the same, livei
variable and by the time clicks occur the for loop has completed andi
is equal tonumber_of_banners
. (Only a dozen @Christoph? Probably at least a dozen this month...) – nnnnnn Sep 18 '12 at 6:07