Why setTimeout() function runs only once?

Shubham picture Shubham · Dec 24, 2010 · Viewed 14.8k times · Source

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??

Answer

BoltClock picture BoltClock · Dec 24, 2010

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

t = window.setInterval("x()",100);