jQuery setinterval and settimeout; In this tutorial, i am going to show you how to use jQuery setTimeout (seconds) & setInterval (seconds) methods.
jQuery setInterval and setTimeout for Interval time
- setTimeout
- setInterval
jQuery setTimeout Method
The setTimeout function executes a script code after a specified delay (in milliseconds).
Syntax of jQuery setTimeout Method
setTimeout(function, milliseconds);
Example of jquery settimeout 1000 seconds
See the following example for how use this setTimeout function; as shown below:
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script> $(document).ready(function(){ $("#btn-timout").click(function(){ setTimeout("alert('Hello World!');", 1000); }); }); </script> </head> <body> <div class="common_box_body"> <button id="btn-timout">Click</button> <p>Click the above given button and wait for 4 seconds. After 4 second will come alert box</p> </div> </body> </html>
Demo for jquery settimeout 1000 seconds
Click the above given button and wait for 4 seconds. After 4 second will come alert box
jQuery setInterval Method
The jQuery setInterval function can be used to continue any work by using a regular time-based trigger.
Syntax of jQuery setInterval Method
setInterval(function, milliseconds);
Example of jquery setinterval for minute
See the following example for how use this setInterval function; as shown below:
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script> $(document).ready(function(){ $("#btn-interval").click(function(){ setInterval("alert('Hello World!');", 3600); }); }); </script> </head> <body> <div class="common_box_body"> <button id="btn-interval">Click</button> <p>Click the above given button and wait for 4 seconds. After 4 second will come alert box continuously</p> </div> </body> </html>
Demo for jquery setinterval 1 minute
Click the above given button and wait for 4 seconds. After 4 second will come alert box continuously
To Remember
The setInterval function performs again and again in the given interval time.The setTimeout function is executed only once in given intervals time. In both functions, 1000 ms = 1 seconds.
Recommended jQuery Tutorials
Recommended:-Get and Set Data Attribute Value in jQuery
Recommended:-jQuery Get Multiple Checkbox Value
Recommended:-jQuery Remove Attribute Disabled
Recommended:-jQuery Select Multiple HTML Elements
Recommended:-jQuery Get Data Id, Text Attribute Value
Recommended:-jQuery Set and Get width and height Of Element
Recommended:-jQuery Clone/Duplicate Html Elements
Recommended:-jQuery Wrap and Unwrap Multiple Html Element
Recommended:-jQuery Ajax Get Method with Example
Recommended:-jQuery Filter Selection of HTML Elements
Recommended:-jQuery Find Sibling with id, Class
Recommended:-jQuery scrollTop Method
Recommended:-jQuery Load External Html Content from Another Page
Recommended:-jQuery Ajax Post Example
Recommended:-jQuery Get/Find Closets Element
Recommended:-jQuery Check Uncheck Checkbox
Recommended:-jQuery Previous Next Sibling Methods