The JavaScript setTimeout function can be used in a jQuery script to automate a task using a single-use, time-based trigger.
Basic setTimeout() Example
Basic setTimeout() Example
1
2
3
| setTimeout( function () { // Do something after 5 seconds }, 5000); |
Tip: you can use the ClearTimeout() function to clear any timer values previously stored.
1
2
| timeout = setTimeout( 'timeout_trigger()' , 3000); clearTimeout(timeout); |
More setTimeout() Examples
1
2
3
4
| jQuery(document).ready( function () { //hide a div after 3 seconds setTimeout( "jQuery('#div').hide();" ,3000 ); }); |
Or in a different way:
1
2
3
4
| jQuery(document).ready( function () { //hide a div after 3 seconds setTimeout( function (){ jQuery( "#div" ).hide(); }, 3000); }); |
No comments:
Post a Comment