jQuery delay() Method - CodingTag
×


jQuery delay()

1640

  • This jQuery method is used to delay the execution of a range of queued functions on a selected HTML element.

Related Topics:

jQuery slideToggle
jQuery animate

jQuery delay

Syntax:

$(selector).delay(speed,functionName);

Parameter description:

  • speed: This parameter used to set the duration of the effect. It can be "slow", "fast" or any time in milliseconds. It is optional.
  • callback: This represents a function which to be executed. It is also optional.

Example:

<html>
<head>
<title> jQuery Example </title>
<script type = "text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<style>
.para1{
background:red;
padding:20px;
}
.para2{
background:yellow;
padding:20px;
}
.para3{
background:green;
padding:20px;
}.para4{
background:blue;
padding:20px;
}
button{
background:green;
padding:10px;
color:white;
border:1px solid green;
}
</style>
<script>
$(document).ready(function(){
$("p").css("display","none");
$("button").click(function(){
$(".para1").delay("fast").fadeIn();
$(".para2").delay("slow").fadeIn();
$(".para3").delay(1000).fadeIn();
$(".para4").delay(2000).fadeIn();
});
});
</script>
</head>
<body>

<h2> jQuery delay() method Example </h2>
<button> Click me! </button>
<p class="para1"> This is paragraph 1. </p>
<p class="para2"> This is paragraph 2. </p>
<p class="para3"> This is paragraph 3. </p>
<p class="para4"> This is paragraph 4. </p>

</body>
</html>

Output:

When you click the button, all paragraphs will fade on different time.



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments