Window clearTimeout() Method

## JavaScript Reference

Overview

## JavaScript Objects

JS Array JS Boolean JS Date JS Math JS Number JS String JS RegExp JS Global

## Browser Objects

Window Navigator Screen History Location

## HTML DOM Objects

DOM Document DOM Elements DOM Attributes DOM Events

## HTML Objects

DOM Anchor DOM Area DOM Base DOM Body DOM Button DOM Form DOM Frame/IFrame DOM Frameset DOM Image DOM Input Button DOM Input Checkbox DOM Input File DOM Input Hidden DOM Input Password DOM Input Radio DOM Input Reset DOM Input Submit DOM Input Text DOM Link DOM Meta DOM Object DOM Option DOM Select DOM Style DOM Table DOM td / th DOM tr DOM Textarea

# Window clearTimeout() Method

Window Object

## Example

Prevent the function set with the setTimeout() to execute:

var myVar;
function myFunction()
{
myVar = setTimeout(function(){alert("Hello")},3000);
}
function myStopFunction()
{
clearTimeout(myVar);
}
Try it yourself »

## 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.

Note: To be able to use the clearTimeout() method, you must use a global variable when creating the timeout method:

myVar = setTimeout("javascript function",milliseconds);

Then, if the function has not already been executed, you will be able to stop the execution by calling the clearTimeout() method.

## Browser Support

The clearTimeout() method is supported in all major browsers.

## Syntax

clearTimeout(id_of_settimeout)

## Parameter Values

Parameter | Description
--- | ---
id_of_settimeout | Required. The ID value of the timer returned by the setTimeout() method

## Return Value

No return value.

## More Examples

## 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:

<button onclick="startCount()">Start count!</button>
<input type="text" id="txt">
<button onclick="stopCount()">Stop count!</button>
<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 startCount()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
</script>
Try it yourself »

Window Object

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE