I am trying to display 4 divs one after eachother using setInterval
Code:
function switchIcon(current, next)
{
document.getElementById(next).innerHTML = "<div class=\"on\"></div>";
document.getElementById(current).innerHTML = "<div class=\"off\"></div>";
}
function timedMsg()
{
var IntervalId1 = 0;
var IntervalId2 = 1;
var IntervalId3 = 2;
var IntervalId4 = 3;
IntervalId1 =setInterval(switchIcon("stepImage1", "stepImage2"),2000);
clearInterval ( IntervalId1);
IntervalId2 =setInterval(switchIcon("stepImage2", "stepImage3"),2000);
clearInterval ( IntervalId2);
IntervalId3 =setInterval(switchIcon("stepImage3", "stepImage4"),2000);
clearInterval ( IntervalId3);
IntervalId4 =setInterval(switchIcon("stepImage4", "stepImage1"),2000);
clearInterval ( IntervalId4);
}
the code is simple,
onLoad timeMsg() is called
then after 2000 milliseconds each setInterval should be called. What i am finding is that only the first setInterval call is being fired and then the scripts stops...
anyone know why...
could it be that all 4 statements are being fired at the same time?
And you will have to use 2000 for the first setTimeout, 4000 for the second etc., because the time is being set from now, not from when the next finishes.
Great wit and madness are near allied, and fine a line their bounds divide.
And you will have to use 2000 for the first setTimeout, 4000 for the second etc., because the time is being set from now, not from when the next finishes.
In fact setTimeout() would be a better choice, I presume.
Bookmarks