JavaScript setInterval
JavaScript setInterval works similar to setTimeout function in JavaScript. setInterval method calls the specified expression after the specified interval of time in milliseconds.
In the previous articles we discussed about the use of setTimeout and clearTimeout methods and done some examples.
JavaScript Timer Examples:
You can see the live samples and examples of JavaScript Timer Events from the following links:
Now we will learn the syntax and use of setInterval function of javascript:
JavaScript setInterval syntax
setInterval( expression, msec, lang);
setInterval function takes 3 parameters
Expression: Name of the function to call or the javascript expression to evaluate.
Msec: Time in milliseconds after which the specified expression is evaluated.
Lang: Optional parameter to specify the scripting language e.g.: Jscript, Javascript, vbscript.
JavaScript setInterval Example
var interval;
function startInterval()
{
interval = setInterval("startTime();",1000);
}
function startTime()
{
document.getElementById('myTime').innerHTML = Date();
}
In the above JavaScript setInterval example, there are two functions startInterval that is called upon when a user clicks on start interval button. startInterval function has setInterval javascript method that calls the other function startTime after regular interval of time i.e. 1000 milliseconds (1 second).
Output:
You can see the output of above discussed code from the following link:
Continue to next tutorial: Javascript clearInterval to learn how to stop timer interval to exit the function execution process.

* will not be published
* hint: http://www.example.com