First, you store the return value for the setTimeout
function:
// Set the timeout
var timeout = setTimeout(function()
{
// Your function here
}, 2000);
Then, when you’re ready to kill the timeout…you just call clearTimeout
with the stored value from the previous call to setTimeout
.
// Then clearn the timeout
clearTimeout(timeout);