Home Tech Geek Web Development Solution to: How do I cancel a setTimeout() call in Javascript?

Get social!


Use clearTimeout().

Set timeout function:

To cancel it:

Here’s a JS Fiddle illustrate:


Just click the “Start Timer” link, wait 5 seconds, and you should get an alert box. Close the alert, click the “Start Timer” link again. This time click the “Stop Timer” link within the 5 seconds and you won’t see the alert box.

Leave a Reply

Bad Behavior has blocked 108 access attempts in the last 7 days.