How to call a function automatically after waiting for some time using jQuery? Last Updated : 17 Feb, 2022 Comments Improve Suggest changes Like Article Like Report In order to run a function automatically after waiting for some time, we are using the jQuery delay() method. The .delay() method in jQuery which is used to set a timer to delay the execution of the next item in the queue.Syntax: $(selector).delay(para1, para2); Approach: When the Button is clicked the process is delayed to the specific time period using .delay() method.Functions or process is queued using .queue() method. After the process or functions are executed, all executed functions are dequeued using .dequeue() method. Example 1: html <!DOCTYPE html> <html> <head> <title>How to call a function automatically after waiting for some time using jQuery</title> <script src="https://code.jquery.com/jquery-1.12.4.min.js"> </script> <style type="text/css"> img { display: none; } </style> </head> <body> <center> <h1 style="color:green;"> GeeksForGeeks </h1> <h3>How to call a function automatically after waiting for some time using jQuery</h3> <button type="button" class="show-image">Click</button> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20190912174307/qwe1.png" /> <script type="text/javascript"> function showImg() { $("img").fadeIn(1500); } $(document).ready(function() { $(".show-image").click(function() { $(this).text('Wait...').delay(1000).queue(function() { $(this).hide(); showImg(); $(this).dequeue(); }); }); }); </script> </center> </body> </html> Output: Example 2: Along with alert method html <!DOCTYPE html> <html> <head> <title>How to call a function automatically after waiting for some time using jQuerye</title> <script src="https://code.jquery.com/jquery-1.12.4.min.js"> </script> <style type="text/css"> img { display: none; } </style> </head> <body> <center> <h1 style="color:green;"> GeeksForGeeks </h1> <h3>How to call a function automatically after waiting for some time using jQuery</h3> <button type="button" class="show-image"> Click </button> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20190912174307/qwe1.png" /> <script type="text/javascript"> function showImg() { $("img").fadeIn(1500); } $(document).ready(function() { $(".show-image").click(function() { $(this).text('Wait...').delay(1000).queue(function() { $(this).hide(); showImg(); $(this).dequeue(); alert("Waiting time is over"); }); }); }); </script> </center> </body> </html> Output: Comment More infoAdvertise with us Next Article How to call a function automatically after waiting for some time using jQuery? S SHUBHAMSINGH10 Follow Improve Article Tags : JavaScript Web Technologies JQuery jQuery-Misc Similar Reads How to call a function when content of a div changes using jQuery ? The task is to call a function when the content of a div is changed. You can achieve this task by using the in-built method known as .change(). In simple words whenever the field is been changed we call a function that will throw a pop-up. .change(): This method will only trigger when some change oc 2 min read How to call functions after previous function is completed in jQuery ? In jQuery, to call a function after a previous function is completed, you can use callback functions. A callback ensures the second function executes only after the first one finishes, maintaining proper sequence in asynchronous operations or animations.SyntaxfunctionName();Approach: This problem ca 3 min read How to set timeout for ajax by using jQuery? In web programming, the Ajax is used so that the resultant data is shown in the one part of the web page, without reloading the page. The user needs to perform the Ajax request and wants the result within a timeframe. In this scenario, the jquery timeout feature is used in the code. Session timeout 4 min read How to implement a function that enable another function after specified time using JavaScript ? Let us assume that we have been given a function add() which takes in two parameters a and b, and returns their sum. We are supposed to implement a function that should be able to call any function after the given delay amount of time. This can be done with the approaches as given below: Approach 1: 2 min read How to create automatic pop-up using jQuery ? In this article, we will be showing you how to make a custom automatic Pop-up box for subscribing to any service. You might have often come across a Pop-up box asking to subscribe to any services when you visit any particular site. Hence in this article, you will learn how to customize that Pop-up b 4 min read How to Automatically Close Alerts using Twitter Bootstrap ? All modern web application uses alerts to show messages to the user. These alerts have a close button to close them or can be closed automatically using Twitter Bootstrap. In this post, we will create automatically closing of alerts using twitter Bootstrap. Basic idea is to use jQuery setTimeout() m 3 min read How to resolve a deferred object when the user clicks a button using jQuery ? A deferred object in jQuery represents an operation that is still in progress and can be resolved at a later time. Deferred objects are often used in jQuery to handle asynchronous operations, such as making AJAX requests or waiting for a DOM element to become available. When a deferred object is res 3 min read How to use jQuery library and call functions from it ? In this article, we will see how we can include the jQuery library in the code & use the different call functions. We will be adding some animation effects to see its uses. jQuery is a lightweight JavaScript library that was built to simplify complex JavaScript tasks by generalizing various conc 7 min read How to perform jQuery Callback after submitting the form ? The after-form-submit is the set of code that is executed after a submit button is fired. Usually, it is used to blank out the form, once the submit is given. For Example, When the login credentials are wrong, the input becomes blank in the form. Approach: First, the elements in a form must be ensur 2 min read How to Delay a JavaScript Function Call using JavaScript ? Delaying a JavaScript function call involves postponing its execution for a specified time using methods like setTimeout(). This technique is useful for timed actions, animations, or asynchronous tasks, enabling smoother user experiences and better control over when certain operations run.There are 3 min read Like