
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery fadeToggle Method
The fadeToggle() method in jQuery is used to toggle between the fadeIn() and fadeOut() methods.
Syntax
The syntax is as follows −
$(selector).fadeToggle(speed,easing,callback)
Above, speed is the speed of the fading effect. The easing can be swing or linear for speed at different animation points. Callback is the function to be executed after the method gets finished.
Example
Let us now see an example to implement the jQuery fadeToggle() method −
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(".btnout").click(function(){ $("div").fadeOut(); }); $(".btnin").click(function(){ $("div").fadeIn(); }); $(".btnfade").click(function(){ $("div").fadeToggle("slow"); }); }); </script> </head> <body> <h2>Java</h2> <div> <p>Java released in 1994. The current version is Java 13.</p> </div> <button class="btnout">Fade out</button> <button class="btnin">Fade in</button> <button class="btnfade">Fade Toggle</button> <p>Click on above buttons to fade out and fade in text.</p> </body> </html>
Output
This will produce the following output −
Above, click on “Fade Toggle” to fade slowly −
Advertisements