PDA

View Full Version : delaying output



side_split2
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++)
{
document.write(address[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.

nikkiH
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.

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

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