- This topic has 0 replies, 1 voice, and was last updated 8 years ago by .
- You must be logged in to reply to this topic.
We generally do setTimeout as
setTimeout("SomeFunction();", 5000); // Means setTimeout is set to 5 seconds
Some defined or custom function in our case it is SomeFunction() which will run after 5 seconds.
But what if you want to cancel or clear or avoid setTimeout after few seconds and before the function SomeFunction() is initiated?
In this condition we need to use clearTimeout function.
Generally to cancel or clear some timeout stuff – the best way to do is the following
1. Put setTimeout in some variable, something like this
var timer = setTimeout("SomeFunction();", 5000);
2. Then now to cancel or clear it, do the following
Affiliate Disclosure: The above links are affiliate links, meaning that if you choose to click through and make a purchase, we will receive a small commission at no cost to you.