jQuery fadeToggle() Method
jQuery fadeToggle() Method
The jQuery fadeToggle()
method will display or hide the matched elements by animating their opacity.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>jQuery fadeToggle() Method</h1>
<button>Fade Toggle</button>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").fadeToggle();
});
});
</script>
</body>
</html>
Syntax
$(selector).fadeToggle(speed, easing, callback);
Parameter Values
Value | Type | Explanation |
---|
speed | Required | Specifies the speed of the fading effect. Possible values are |
easing | Optional | Specifies the easing function to use for the transition. Default value is "swing" Possible values are
|
callback | Optional | Specifies a function to be called once the animation is completed. |
fadeToggle() with Speed
In the following example, we will specify the speed of the fading effect for fadeToggle()
method to 2000ms (2 seconds).
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>jQuery fadeToggle() Method</h1>
<button>Fade Toggle</button>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").fadeToggle(2000);
});
});
</script>
</body>
</html>
fadeToggle() with Easing
In the following example, we will specify the easing function for fadeToggle()
method to linear.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>jQuery fadeToggle() Method</h1>
<button>Fade Toggle</button>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").fadeToggle(2000, "linear");
});
});
</script>
</body>
</html>
fadeToggle() with Callback
In the following example, we will call a function (myFunction) once the fading effect for fadeToggle()
method is finished.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>jQuery fadeToggle() Method</h1>
<button>Fade Toggle</button>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").fadeToggle(2000, "linear", myFunction);
});
});
function myFunction(){
alert("Toggle is completed");
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 99.5% of jQuery Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in jQuery.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.
Share this Page
Meet the Author