- This topic has 0 replies, 1 voice, and was last updated 9 years, 1 month 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 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 the 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
Founder of WittySparks
Sravan is the Founder of WittySparks, a global content publishing platform that offers witty stories and information across multiple industry domains. Under his leadership, WittySparks today has become a go-to destination for in-depth healthcare, business, and marketing topics. Besides, Sravan is a highly experienced web designer and developer and currently works at Oracle. You can connect with him on Twitter or LinkedIn and initiate a chat.
If you make a purchase from WittySparks links, we will receive a small commission. See our Affiliate Disclosure.