How to call a function automatically after waiting for some time in jQuery

  1395 views   2 years ago jQuery

Use the jQuery delay() method

You can use the jQuery delay() method to call a function after waiting for some time. Simply pass an integer value to this function to set the time interval for the delay in milliseconds.

Let's check out an example to understand how this method basically works:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>jQuery Execute a Function after Certain Time</title>
        display: none;
<script src=""></script>
function showImage(){
        $(this).text('loading...').delay(1000).queue(function() {
            showImage(); //calling showimage() function
    <button type="button" class="show-image">Show Image</button>
    <img src="../images/kites.jpg" alt="Flying Kites">


Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]