1. js setTimeout & setInterval
By Arif Mahmud Rana
Web Developer Technobd
2. window.setTimeout
Calls a function or executes a code snippet after
a specified delay.
Syntax :
var timeoutID = window.setTimeout(func, delay,
[param1, param2, ...]);
var timeoutID = window.setTimeout(code,
delay);
clearTimeout(timeoutID);//clearing setTimeout
3. Examples
var x = document.getElementById("txt");
var myVar = setTimeout(function(){x.value="2
seconds"},2000);
clearTimeout(myVar);//clearing setTimeout
5. Window.setInterval
Calls a function or executes a code snippet
repeatedly, with a fixed time delay between
each call to that function.
Syntax :
var intervalID =
window.setInterval(func, delay[, param1, para
m2, ...]);
var intervalID = window.setInterval(code, delay);
clearInterval(intervalID);//clearing setInterval
6. Examples
var x = document.getElementById("txt");
var myVar = setInterval(function(){x.value+="2
seconds"},2000);
setInterval(myVar);//clearing setInterval