Brandon schrieb:
I am finishing up a small script using the jQuery library, and I am
struggling with a onclick function:
for (i=0; i<elements.length; i++) {
$('#'+settings.instancename+'-nav-'+String(i+1)).click(function() {
jumpTo(i);
});
}
Now I know what the problem is, when I call to the function jumpTo(i),
it passes i as a reference (every click ends up as 5, which is the
last value of i). How can I pass the value of i, and not the
reference of i?
I think the easiest approach is to copy the value:
for (i=0; i<elements.length; i++) {
var ix = i;
$('#'+settings.instancename+'-nav-'+String(ix+1)).click(function() {
jumpTo(ix);
});
}
--
Jörn Zaefferer
http://bassistance.de