I am sure I simply didn't have enough coffee yet to see clearly, and this seems trivial, however, I have a for loop that passes some functions in a jQuery plugin. var i is passed, and of course, passes the last value of i, instead of the value it was assigned when passing through.
for (var i = 1; i < 3 + 1; i++) {
$('#div' + i).plugin({ // i returns correctly here
onDelete: function () {
alert("Deleting #" + i); // i returns 4 every time - last value of i
}
});
}
How do I "copy" i, so it is returned as I expect? I have a workaround, but I would love to know, so I can put my head in the sand.