jQuery fadeOut() Method

You are Here:

jQuery fadeOut() Method

The jQuery fadeOut() method will hide the matched elements by fading them to transparent.

This method is often used with jQuery fadeIn() method.

Example

HTML Editor
<!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 fadeOut() Method</h1> <button id="myFadeOut">Fade Out</button> <button id="myFadeIn">Fade In</button> <script> $(document).ready(function(){ $("#myFadeOut").click(function(){ $("p").fadeOut(); }); $("#myFadeIn").click(function(){ $("p").fadeIn(); }); }); </script> </body> </html>

Syntax

$(selector).fadeOut(speed, easing, callback);

Parameter Values

ValueTypeExplanation
speedOptionalSpecifies the speed of the fading effect.
Default value is 400 milliseconds.
Possible values are
  • "slow"
  • "fast"
  • milliseconds
easingOptionalSpecifies the easing function to use for the transition.
Default value is "swing"
Possible values are
  • "swing"
  • "linear"
callbackOptionalSpecifies a function to be called once the animation is completed.

fadeOut() with Speed

In the following example, we will specify the speed of the fading effect for fadeOut() method to 2000ms (2 seconds).

Example

HTML Editor
<!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 fadeOut() Method</h1> <button id="myFadeOut">Fade Out</button> <button id="myFadeIn">Fade In</button> <script> $(document).ready(function(){ $("#myFadeOut").click(function(){ $("p").fadeOut(2000); }); $("#myFadeIn").click(function(){ $("p").fadeIn(); }); }); </script> </body> </html>

fadeOut() with Easing

In the following example, we will specify the easing function for fadeOut() method to linear.

Example

HTML Editor
<!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 fadeOut() Method</h1> <button id="myFadeOut">Fade Out</button> <button id="myFadeIn">Fade In</button> <script> $(document).ready(function(){ $("#myFadeOut").click(function(){ $("p").fadeOut(2000, "linear"); }); $("#myFadeIn").click(function(){ $("p").fadeIn(); }); }); </script> </body> </html>

fadeOut() with Callback

In the following example, we will call a function (myFunction) once the fading effect for fadeOut() method is finished.

Example

HTML Editor
<!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 fadeOut() Method</h1> <button id="myFadeOut">Fade Out</button> <button id="myFadeIn">Fade In</button> <script> $(document).ready(function(){ $("#myFadeOut").click(function(){ $("p").fadeOut(2000, "linear", myFunction); }); $("#myFadeIn").click(function(){ $("p").fadeIn(); }); }); function myFunction(){ alert("fadeOut 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