jQuery delay()

The jQuery delay() method can be used to make a delay between the queued jQuery effects.

Example:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").delay(3000).fadeIn();
});
});
</script>
</head>
<body>
<button>Click me</button><br>
<div id="div1" style="width:90px;height:90px;display:none;background-color:black;"></div><br>
</body>
</html>

Syntax:

$(selector).delay (speed, queueName)

Speed: Speed is an optional parameter whose value specifies the speed of the delay. It can take values as: “fast”, “slow” or values in milliseconds.

queueName: queueName is also an optional parameter that is used to specify the name of the queue. The default value of queueName is “fx”.

Example:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").delay("fast").fadeIn();
$("#div2").delay("slow").fadeIn();
$("#div3").delay(1000).fadeIn();
$("#div4").delay(2000).fadeIn();
$("#div5").delay(4000).fadeIn();
});
});
</script>
</head>
<body>
<p>Click to fade in boxes with a different delay time.</p>
<button>Click me</button><br><br>
<div id="div1" style="width:90px;height:90px;display:none;background-color:black;border-radius:120px"></div><br>
<div id="div2" style="width:90px;height:90px;display:none;background-color:green;border-radius:120px"></div><br>
<div id="div3" style="width:90px;height:90px;display:none;background-color:blue;border-radius:120px"></div><br>
<div id="div4" style="width:90px;height:90px;display:none;background-color:red;border-radius:120px"></div><br>
</body>
</html>