This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

clearInterval

Summary

Cancels the interval previously started using the setInterval method.

Method of dom/Windowdom/Window

Syntax

 window.clearInterval(/* see parameter list */);

Parameters

timerID

Data-type
Number

Integer that specifies the interval to cancel. This value must have been previously returned by the setInterval method.

Return Value

No return value

Examples

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>setInterval/clearInterval example</title>
<script>
var nIntervId;

function changeColor() {
  nIntervId = setInterval(flashText, 500);
}

function flashText() {
  var oElem = document.getElementById("my_box");
  oElem.style.color = oElem.style.color == "red" ? "blue" : "red";
}

function stopTextColor() {
  clearInterval(nIntervId);
}
</script>
</head>

<body onload="changeColor();">
<div id="my_box" style="color: red;">
<p>Hello World</p>
</div>
<button onclick="stopTextColor();">Stop</button>

</body>
</html>

Attributions