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.
Be First to Comment