Cancel/Kill Window. setTimeout() Before It Happens

Cancel/Kill Window. setTimeout() Before It Happens

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?

2 Answers

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

clearTimeout(timer1)
7

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

3
Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.