I am trying to use the value of a for loop counter inside a queued function, for example:
for(var i=0; i<5; i++)
$(document.body).queue(function(){alert('i=' + i); $(this).dequeue();}).delay(1000);
then I get:
i=0, i=5, i=5, i=5, i=5
I think this is because i
has changed while delay(1000)
..
What can I do to get the right values of i
, i.e:
i=0, i=1, i=2, i=3, i=4