Javascript examples for Browser Object Model:Window clearTimeout
The clearTimeout() method clears a timer set with the setTimeout() method.
Parameter | Description |
---|---|
id_of_settimeout | Required. The ID value of the timer returned by the setTimeout() method |
No return value
The following code shows how to Prevent the function set with the setTimeout() to execute:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <button onclick="myStopFunction()">Stop the alert</button> <script> var myVar;//from w w w. j a va 2 s .c o m function myFunction() { myVar = setTimeout(function(){ console.log("Hello"); }, 3000); } function myStopFunction() { clearTimeout(myVar); } </script> </body> </html>