[jQuery] need to get value when event is bound, not when it runs.
I hope this will make sense to somebody. I currently have code which
looks like this.
for (var i = 0; i < 10; i++) {
$('#textBox_' + i).blur(function() {
alert(i);
});
};
So, that should bind 10 blur events to 10 textboxes and when i "blur"
the first textbox it should alert(1). When I blur the second textbox
it should blur(2).
the problem is that all of the textboxes alert(10) when you blur them
because by the time the event happens the looping has finished and "i"
is 10.
How do I use the value of "i" at bind time in my function, rather than
the value of I when it is fired.
I'm not quite understanding scope/context in javascript yet!