Javascript examples for Browser Object Model:Window clearInterval
The clearInterval() method clears a timer set with the setInterval() method.
Parameter | Description |
---|---|
id_of_setinterval | Required. The ID of the timer returned by the setInterval() method |
No return value
The following code shows how to Display the current time as a clock.
<!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>