jQuery setTimeout() Function and its examples
setTimeout
is a jQuery function which executes a code snippet or another function after a specified delay (in seconds or milliseconds). Many Time we need to run or executes some code snippet or function after some time or some delay, can use setTimeout() function.
Syntax
the syntax for setTimeout
is as follows:
1 |
setTimeout(function(), [delay, param1, param2, ...]); |
setTimeout(function(), [delay, param1, param2, …]);
1 |
setTimeout(code, [delay]); |
Examples of Use
You can call another function inside setTineout that will execute after specified time.
1 2 3 4 |
function explode(){ alert("Boom!"); } setTimeout(explode, 2000); |
A variable that refers to a function:
1 2 3 4 |
var explode = function(){ alert("Boom!"); }; setTimeout(explode, 2000); |
Or an anonymous function:
1 2 3 |
setTimeout(function(){ alert("Boom!"); }, 2000); |
[paypal-donation]