Window clearInterval()Method
Example
Display the current time (the setInterval() function executes the function once every second, like a watch). Use clearInterval() to stop execution:
Try it Yourself »
Definition and Usage
The clearInterval() method cancels the timed execution operation set by the setInterval() function.
The parameter of the clearInterval() method must be the ID value returned by setInterval().
Note:To use the clearInterval() method, use a global variable when creating the timed execution operation:
myVar = setInterval("javascript 函数", milliseconds);
You can use the clearInterval() method to stop execution.
Browser Support
The numbers in the table indicate the first browser version number that supports the property.
| Method | |||||
|---|---|---|---|---|---|
| clearInterval() | 1.0 | 4.0 | 1.0 | 1.0 | 4.0 |
Syntax
clearInterval(id_of_setinterval)
| Parameter | Description |
|---|---|
| id_of_setinterval | The return value obtained when calling the setInterval() function. Using this returned identifier as a parameter, you can cancel the timed execution operation set by that setInterval(). |
Technical Details
| Return Value: | No return value. |
|---|
More Examples
Example
Switch the background color every 300 milliseconds, until stopped with clearInterval():
Try it Yourself »
Example
Use setInterval() and clearInterval() to create a dynamic progress bar:
Try it Yourself »
Related Pages
Window Object:setInterval() Method
Window Object:setTimeout() Method
Window Object:clearTimeout() Method
Other Extensions
Window Object