window.clearTimeout
clearTimeout — Clears a previously setTimeout.
Description
clearTimeout(timeout id)
Parameters
Name |
Description |
Type |
Default |
Optional |
id |
The id of the setTimeout. |
timeout |
|
No |
Examples
Example #1 – clearTimeout example
var timeout = setTimeout(function () {
console.log('Will never be executed.');
}, 100);
clearTimeout(timeout);
Example #2 – clearTimeout example
var timeout;
var loop = function () {
timeout = setTimeout(function () {
console.log('Recursivle executes until cleared.');
loop();
}, 200);
};
setTimeout(function () {
console.log('Clearing recursive timeout.');
clearTimeout(timeout);
}, 1500);
loop();
See also
External references