jQuery fadeTo() with speed, opacity and callback

Introduction

Gradually change the opacity of the p element

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*ww w.  j  a va 2 s.  c  om*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").fadeTo(2000, 0.2, function(){
      document.getElementById("demo").innerHTML = "The fadeTo effect is finished!";
    });
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<button>test</button>

<p>This is a paragraph.</p>

</body>
</html>



PreviousNext

Related