JS variable scope missunderstanding
- by meo
I have a little problem:
slideHelpers.total = 4
for (i=1;i <= slideHelpers.total; i++) {
$('<a href="#">' + i + '</a>').bind('click', function(){ alert('go to the ' + i + ' slide')}).appendTo('.slideaccess')
}
the alert gives out 5 what is logic, because when the function click triggers i is actually 5. But i would like to have the same i as in my <a> tag. What is the best way to handle this?
I could put i in the data() of the <a> tag for example but i am sure there is a easier way.