Window setInterval() Method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window setInterval

Description

The setInterval() method calls a function or evaluates an expression at intervals in milliseconds.

Syntax

window.setInterval(function,milliseconds, param1, param2,...);

Parameter Values

Parameter Description
functionRequired. The function that will be executed
millisecondsRequired. The intervals to execute the code.
param1, param2, ... Optional. Additional parameters to pass to the function

Return Value:

A Number, representing the ID value of the timer that is set.

The following code shows how to create a clock.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var myVar = setInterval(function(){ myTimer() }, 1000);

function myTimer() {//from w ww . j a v  a  2s  .c  o m
    var d = new Date();
    var t = d.toLocaleTimeString();
    document.getElementById("demo").innerHTML = t;
}
</script>

</body>
</html>

Related Tutorials