Window clearTimeout () method
Definition and Usage
clearTimeout () method to cancel the () the setTimeout timeout method settings.
Parameters clearTimeout () method must be the ID value returned by the setTimeout ().
grammar
clearTimeout(id_of_settimeout)
Browser Support
All major browsers support clearTimeout () method
Examples
Examples
The following example, there is a "Start count!" Button to start a timer, an input field, you will always counts, and a button to stop the timer "Stop count!":
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;
}
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;
}
try it"
Window object