jQuery fadeOut() with Example

jQueryWeb DevelopmentFront End Technology

The fadeOut() method in jQuery is used to change the opacity, for selected elements, from visible to hidden.

Syntax

The syntax is as follows −

$(selector).fadeOut(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 fadeOut() 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();
      });
   });
</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>
<p>Click on above buttons to fade out and fade in text.</p>
</body>
</html>

Output

This will produce the following output −

Click on the above “Fade out” button to fade out the text −

Click on the above “Fade in” button now to fade in (display) the text −

raja
Published on 12-Nov-2019 16:17:38
Advertisements