Window clearTimeout() Method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window clearTimeout

Description

The clearTimeout() method clears a timer set with the setTimeout() method.

Parameter Values

ParameterDescription
id_of_settimeout Required. The ID value of the timer returned by the setTimeout() method

Return Value:

No return value

The following code shows how to Prevent the function set with the setTimeout() to execute:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>
<button onclick="myStopFunction()">Stop the alert</button>

<script>
var myVar;//from   w w  w. j a va 2 s .c  o m

function myFunction() {
    myVar = setTimeout(function(){ console.log("Hello"); }, 3000);
}

function myStopFunction() {
    clearTimeout(myVar);
}
</script>

</body>
</html>

Related Tutorials