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

Adding a Delay Timer

function myTimer () {   alert("Timer Function Executed"); } var timerId = setTimeout(myTimer, 10000);

To simply delay the execution of code for a certain amount of time, use the setTimeout(code, ms) method, where code is either a statement or a function that executes when the time expires. ms is the number of milliseconds. For example, to execute a function named myTimer() in 10 seconds, you would use the following:

setTimeout(myTimer, 10000);

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