Window clearInterval() Method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window clearInterval

Description

The clearInterval() method clears a timer set with the setInterval() method.

Parameter Values

Parameter Description
id_of_setinterval Required. The ID of the timer returned by the setInterval() method

Return Value:

No return value

The following code shows how to Display the current time as a clock.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<button onclick="myStopFunction()">Stop time</button>

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

function myTimer() {//  w  w w  .  ja  v a2s .  c o m
    var d = new Date();
    var t = d.toLocaleTimeString();
    document.getElementById("demo").innerHTML = t;
}

function myStopFunction() {
    clearInterval(myVar);
}
</script>

</body>
</html>

Related Tutorials