I’m trying to attach a dynamic .change() function to a list of elements:
els = new Array('#element1','#element2');
for (i=1; i < 3; i++){
$(els[i]).change(function(){
alert(i);
});
}
This does not work as desired because i is not passed into the function, but is instead always equal to the last iteration, ie, 2. How do I pass a value into the change(function{})?
Two ways of doing this.