Prev Demo
Stopping The Run Timer By Using Cleartimeout Method In Javascript
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Stopping run timer.</h1> <label id="lblText">0</label> <input type="button" id="btnTest" onclick="TestFunction()" value="Start Timer" /> <input type="button" id="btnStop" value="Stop Timer" onclick="StopCount()" /> <script> var count = 0; function TestFunction() { count++; document.getElementById("lblText").innerHTML = count; t = setTimeout("TestFunction()", 1000); } function StopCount() { clearTimeout(t); } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output