How to make a jQuery function call after “X” seconds?

To make a jQuery function call after “X” seconds, use the siteTimeout() method.

On button click, set the following and fade out the element. Here, we have also set the milliseconds. This is the delay that would occur before fading an element:

$("#button1").bind("click",function() {
   setTimeout(function() {
      $('#list').fadeOut();}, 4000);

You can try to run the following code to learn how to work with setTimeout() method in jQuery:


 Live Demo

<!DOCTYPE html>
   <script src=""></script>
         $("#button1").bind("click",function() {
            setTimeout(function() {
               $('#list').fadeOut();}, 4000);

<input type="button" id="button1" value="Fade Out" />
<div id="list">
<p>The above data will fade out after 4 seconds</p>

Updated on: 20-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started