You are here: Reference > JavaScript > client-side > HTML DOM > methods > clearInterval (window)

clearInterval method (window)

Browser support:
Clears the periodically repeated action that was previously set by the setInterval method.
If the action was registered with the setTimeout method, use the clearTimeout method to remove it.

Syntax:

object.clearInterval (intervalID);
You can find the related objects in the Supported by objects section below.

Parameters:

intervalID
Required. Integer that specifies the identifier of the timer returned by the setInterval method.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the clearInterval method:
<head>
    <script type="text/javascript">
        var number = 0;
        var timerID = null;
        function StartCounter () {
            if (timerID === null) { // to avoid multiple registration
                timerID = setInterval (DisplayNumber, 200);
            }
        }
        function DisplayNumber () {
            if (number > 9) {
                clearInterval (timerID);
                return;
            }
            document.getElementById ("output").innerHTML += number;
            number++;
        }
    </script>
</head>
<body>
    <button onclick="StartCounter ();">Click to count!</button>
    <textarea id="output"></textarea>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content