JavaScript:
var quotes = new Array();
quotes[0] = "message 0";
quotes[1] = "message 1";
var qText = document.getElementById('qText');
for (i = 0; i < quotes.length; i++) {
setInterval(function() { qText.innerHTML = quotes[i]; }, 2000);
}
HTML:
<p class="qText" id="qText">Predefined text</p>
The innerHTML of qText changes to undefined, instead of changing into quotes[0], followed by quotes1. Now I tried debugging it by using alert() inside the setInterval function to give me the index of the for loop, and it said “2” both times. So, how would I have the for loop paused instead of setInterval creating new threads and incrementing the index?
I think this is you want, not a loop.