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

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

In this post we will give you information about How to call a function automatically after waiting for some time in jQuery. Hear we will give you detail about How to call a function automatically after waiting for some time in jQueryAnd how to use it also give you demo for it if it is necessary.

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">
<head>
<meta charset="utf-8">
<title>jQuery Execute a Function after Certain Time</title>
<style>
    img{
        display: none;
    }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
function showImage(){
    $("img").fadeIn(500);
}
$(document).ready(function(){ 
    $(".show-image").click(function(){
        $(this).text('loading...').delay(1000).queue(function() {
            $(this).hide();
            showImage(); //calling showimage() function
            $(this).dequeue();
        });        
    });
});
</script>
</head>
<body>
    <button type="button" >Show Image</button>
    <img src="http://tridentsportscars.com/?big=..https://onlinecode.org/images/kites.jpg" alt="Flying Kites">
</body>
</html>

 

Hope this code and post will helped you for implement How to call a function automatically after waiting for some time in jQuery. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US