O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cancel a Timer

function myTimer () {   alert("Timer Function Executed"); } var timerId = setTimeout(myTimer, 10000); clearTimeout(timerId); //timer will not execute

At any point before the time runs out and the code is executed, you can clear the timer by calling the clearTimeout(id) method using the ID returned from setTimeout(). Once the timer has been cleared, it does not execute. You need to keep track of the ID returned from setTimeout() using a variable.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required