Prev Demo
JavaScript
>
Cleartimeout
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Stopping alert before displaying on the window.</h1> <p>Click the "Alert" button to get the alert. <br />Click the "Stop Alert" button to stop the alert. (We must click before the alert display time on window, the alert display time is 4 seconds)</p> <input type="button" value="Alert" onclick="myAlert()"/> <input type="button" value="Stop Alert" onclick="myStopAlert()"/> <script> var a; function myAlert() { a = setTimeout(function () { alert("TechFunda") }, 4000); } function myStopAlert() { clearTimeout(a); } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output