Cancel/kill window.setTimeout() before it happens

JavascriptJquery

Javascript Problem Overview


I have a few places where I use the line below to clear out a status, for example. I have a few of these that hang out for 10 seconds or more and if the user gets clicking around the action can occur at incorrect time intervals.

window.setTimeout(function() { removeStatusIndicator(); }, statusTimeout);

Is it possible to cancel or kill this with some jQuery or JavaScript code, so I don't have this process hanging around?

Javascript Solutions


Solution 1 - Javascript

var timer1 = setTimeout(function() { removeStatusIndicator(); }, statusTimeout);

clearTimeout(timer1)

Solution 2 - Javascript

The window.clearTimeout() should do what you are trying to achieve.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionToran BillupsView Question on Stackoverflow
Solution 1 - JavascriptDiodeus - James MacFarlaneView Answer on Stackoverflow
Solution 2 - JavascriptFlorin ToaderView Answer on Stackoverflow