Prev Demo
Clearinterval Method Stop The Current Timer Set With Setinterval In Javascript.
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Stopping the setInterval run time with the clearInterval method.</h1> <p>Click the below button to stop the current run time.</p> <p id="myId"></p> <input type="button" value="Stop" onclick="myStoptime()"/> <script> var myTime = setInterval(function () { myRuntime() }, 1000); function myRuntime() { var a = new Date(); var b = a.toLocaleTimeString(); document.getElementById("myId").innerHTML = b; } function myStoptime() { clearInterval(myTime); } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output