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);

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.