jQuery toggle() with speed and callback

Introduction

Toggle between hide() and show()

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/* w w  w.  jav a 2  s.com*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").toggle(1000, function(){
      document.getElementById("demo").innerHTML = "The toggle() method is finished!";
    });
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<p>This is a paragraph.</p>

<button>Test</button>

</body>
</html>



PreviousNext

Related