Clear the timer in JavaScript
Description
The following code shows how to clear the timer.
Example
<!-- w ww . j a v a2s . com-->
<!DOCTYPE HTML>
<html>
<body>
<script type="text/javascript">
var num = 0;
var max = 10;
var intervalId = null;
function incrementNumber() {
document.writeln(num++);
//if the max has been reached,
//cancel all pending executions
if (num == max) {
clearInterval(intervalId);
document.writeln("Done");
}
}
intervalId = setInterval(incrementNumber, 500);
</script>
</body>
</html>
The code above generates the following result.
Javascript Tutorial Timer Event
Create text move animation with timer in Ja...
Fire Timer event in JavaScript
Set the timeout for the timer according to ...
Start a timer and cancel a timer in JavaScr...
Stop a time out timer in JavaScript
Use timer in JavaScript
Use window.clearInterval() to stop a timer ...
Use window.clearTimeout() to stop timer in ...
Clear the timer in JavaScript
Create a time out timer in JavaScriptCreate text move animation with timer in Ja...
Fire Timer event in JavaScript
Set the timeout for the timer according to ...
Start a timer and cancel a timer in JavaScr...
Stop a time out timer in JavaScript
Use timer in JavaScript
Use window.clearInterval() to stop a timer ...
Use window.clearTimeout() to stop timer in ...