jQuery fadeTo() Method

The fadeTo() method in jQuery is used to gradually change the opacity for selected elements to a specified opacity.


The syntax is as follows −


Above, speed is the speed of the fading effect, whereas opacity specifies the opacity to fade to. 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.


Let us now see an example to implement the jQuery fadeTo() method −

<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
         $("div").fadeTo(1500, 0.5);
<p>Java released in 1994. The current version is Java 13.</p>
<button class="btnout">Fade out</button>
<button class="btnin">Fade in</button>
<button class="btnfade">Fade</button>
<p>Click on above buttons to fade out and fade in text.</p>


This will produce the following output −

Click on the “Fade” above to gradually fade −

Updated on: 12-Nov-2019


Kickstart Your Career

Get certified by completing the course

Get Started