The fadeToggle() Method in jQuery toggles between the fadeIn() and fadeOut() methods. If elements are faded in, fadeToggle() will fade out. If elements are faded out, fadeToggle() will fade in.
Syntax:
$(selector).fadeToggle(speed, easing, callback)
Parameters: This method accepts three parameters as mentioned above and described below:
- Speed: It is an optional parameter and used to specify the speed of the fading effect. The default value of speed is 400 millisecond. The possible value of speed are:
- milliseconds
- “slow”
- “fast”
- easing: It is an optional parameter and used to specify the speed of element to different points of animation. The default value of easing is “swing”. The possible value of easing are:
- “swing”
- “linear”
- callback: It is optional parameter. The callback function is executed after fadeToggle() method is completed.
Below examples illustrate the fadeToggle() method in jQuery:
Example 1: This example display the fadeToggle() method effect in given speed. The speed can be set in terms of milliseconds.
<!DOCTYPE html> <html> <head> <title> jQuery fadeToggle() Method </title> <style> #Outer { border: 1px solid black; padding-top: 40px; height: 140px; background: green; display: none; } </style> <script src= </script> </head> <body style = "text-align:center;"> <div id= "Outer"> <h1 style = "color:white;" > GeeksForGeeks </h1> </div><br> <button id = "btn"> Fade Toggle </button> <!-- Script to use fadeToggle() Method --> <script> $(document).ready(function() { $("#btn").click(function() { $("#Outer").fadeToggle(1000); }); }); </script> </body> </html> |
Output:
- Before click on the button:
- After first click on the button:
- After second click on the button:
Example 2: This example display the fadeToggle() method effect with swing easing. The easing is used to set the speed of element in different points of the animation.
<!DOCTYPE html> <html> <head> <title> jQuery fadeToggle() Method </title> <style> #Outer { border: 1px solid black; padding-top: 40px; height: 140px; background: green; display: none; } </style> <script src= </script> </head> <body style = "text-align:center;"> <div id= "Outer"> <h1 style = "color:white;" > GeeksForGeeks </h1> </div><br> <button id = "btn"> Fade Toggle </button> <script> $(document).ready(function() { $("#btn").click(function() { $("#Outer").fadeToggle("swing"); }); }); </script> </body> </html> |
Output:
- Before click on the button:
- After first click on the button:
- After second click on the button:
Recommended Posts:
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery UI | position() Method
- JQuery | parseHTML() method
- jQuery | add() method with Example
- jQuery | not() method with Examples
- jQuery | ajaxStart() Method
- JQuery UI | Progressbar method
- jQuery | get() Method
- jQuery | fadeIn() Method
- jQuery | delegate() Method
- jQuery | outerHeight() Method
- jQuery | event.isDefaultPrevented() Method
- jQuery | outerWidth() Method
- jQuery | before() Method
- jQuery | off() Method
- jQuery | html() Method
- jQuery | triggerHandler() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

