setTimeout () запустит команду только один раз. В этом случае setInterval () является вашим другом.
var iFrequency = 5000; // expressed in miliseconds
var myInterval = 0;
// STARTS and Resets the loop if any
function startLoop() {
if(myInterval > 0) clearInterval(myInterval); // stop
myInterval = setInterval( "doSomething()", iFrequency ); // run
}
function doSomething()
{
// (do something here)
}
из кода ...
<input type="button" onclick="iFrequency+=1000; startLoop(); return false;"
value="Add 1 second more to the interval" />