I have a set of <span>
with numbered Ids, i want to add class to <span>
with Id=1
wait for 3 second remove class than add class to <span id=2>
and so and so forth...
how to get this code work. while
loop is unable to call setTimeout
can any one help?
var spanSet = 4;
var spanId = 1;
while (spanSet != 0) {
changeClass();
spanSet--;
}
function changeClass() {
$('#' + spanId).addClass("hilite");
setTimeout(remove, 1000);
spanId++;
}
function remove() {
alert('remove');
$('#' + spanId).removeClass("hilite");
return true;
}
spanId
in the while header (instead ofspanSet
)?