View Full Version : delaying output

Sep 17th, 2007, 06:43 PM
There is an array. Each element in this array contains an image tag. There is a for loop and this is what it looks like:

for(i=0; i<=152; i++)

This outputs to screen all images (Which is good so far), but when executing:

for(i=0; i<=152; i++)
setTimeout (document.write(address[i]), 50*i)

only the first image is displayed. My question is what can I do to get all images displayed with a slight pause in between each. You don't have to use setTimeout. Please help.

Sep 17th, 2007, 07:33 PM
Don't use document.write. It's old, and tends to have bad side effects like wiping out the current document content, depending on where you put it.

Add the images using the document object model. See createElement and appendChild.

Once you do that, see if your problem persists.

Sep 17th, 2007, 07:35 PM
var myTimer = setInterval(
document.getElementById("myLabel").innerHTML += "Write Something";

This delays the process of writing: "Write Something" inside a label. You can replace it with your images.