Prev Demo
JavaScript
>
Clearinterval
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Stop the current run time by using 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