Possible Duplicate:
Javascript for loop and setTimeout issue
I want this loop to change the html inside #leftValue from 0 to leftValue, start with 0 and rise up until leftValue value – but instead it changing the html inside #leftvalue to the value of leftValue without starting with 0.
any idea what am i doing wrong?
for (i=0; i<leftValue; i++)
{
changeLeft(i);
}
function changeLeft(num)
{
var leftTimer = setTimeout(function(){$('#leftValue').html(num+'%')},1000);
}
All your timers are registered at the same time, and will run 1000ms later (thus also all at the same time). You could have the timeout set to e.g.
num * 1000. That way, the time a certainnumshows up is dependent on thatnum.