Window setInterval() Method

Definition and Usage

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

The setInterval() method will continue calling the function until
clearInterval() is called, or the window is

The ID value returned by setInterval() is used as the parameter for the clearInterval() method.

Tip: 1000 ms = 1 second.




Parameter Description
code Required. The function that will be executed
millisec Required. The intervals (in milliseconds) on how often to execute the
lang Optional. JScript | VBScript | JavaScript



Call the clock() function every 1000 millisecond. The clock() function
updates the clock. The example
also have a button to stop the clock:



<input type=”text” id=”clock”>

<script language=javascript>

var int=self.setInterval(function(){clock()},1000);

function clock()


var d=new Date();

var t=d.toLocaleTimeString();




<button onclick=”int=window.clearInterval(int)”>Stop</button>