Window clearTimeout() Method
Window Object
Definition and Usage
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.
Syntax
clearTimeout(id_of_settimeout)
Browser Support

The clearTimeout() method is supported in all major browsers.
Example
Example
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:
<html>
<head>
<script>
var c=0;
var t;
var timer_is_on=0;
function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout(function(){timedCount()},1000);
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onclick="doTimer()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onclick="stopCount()">
</form>
</body>
</html>
Try it yourself »
Window Object
Thank You For Helping Us!
Your message has been sent to W3Schools.
Close [X]