Prevent the function set with the setTimeout() to execute:
More "Try it Yourself" examples below.
The clearTimeout() method clears a timer set with the setTimeout() method.
The ID value returned by setTimeout() is used as the parameter for the clearTimeout() method.
Note: To be able to use the clearTimeout() method, you must use a global variable when creating the timeout method:
Then, if the function has not already been executed, you will be able to stop the execution by calling the clearTimeout() method.
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
clearTimeout() | 1.0 | 4.0 | 1.0 | 1.0 | 4.0 |
Parameter | Description |
---|---|
id_of_settimeout | Required. The ID value of the timer returned by the setTimeout() method |
Return Value: | No return value |
---|
The following example has a "Start count!" button to start a timer, an input field that will count forever, and a "Stop count!" button that will stop the timer:
Window Object: setTimeout() Method
Window Object: setInterval() Method
Window Object: clearInterval() Method