Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why setTimeout() function runs only once?

I am making a javascript bookmarklet that resizes all images, periodically.

javascript: function x(){
    for(i=0;i<=document.getElementsByTagName('img').length;i++)
        document.getElementsByTagName('img')[i].width+=1;
};
t = window.setTimeout("x()",100);
void(0);

But it runs only once. What is the problem here??

like image 724
Shubham Avatar asked Dec 24 '10 04:12

Shubham


People also ask

Does setTimeout run once?

That's because setTimeout() is supposed to run only once. In order to fire an event on set intervals user setInterval() .

Does setTimeout run multiple times?

setTimeout() only runs once, and you said you'd like it to run every 3 minutes, and you'll want to use setInterval() for that.

How many times does setTimeout run?

2 Answers. Show activity on this post. setTimeout will only execute once.

Why is the setTimeout () function used?

The setTimeout function is a native JavaScript function. It sets a timer (a countdown set in milliseconds) for an execution of a callback function, calling the function upon completion of the timer.


1 Answers

Are you looking for setInterval() instead of setTimeout() by any chance?

t = window.setInterval("x()",100);
like image 128
BoltClock Avatar answered Oct 06 '22 17:10

BoltClock