Javascript Ajax jQuery Html PHP Example Quiz New MORE
Need a Website Or Web Application.Contact : +91 9437911966 (Whatsapp) Note: Paid Service

jQuery toggle()


You can also toggle between hiding and showing an element by using toggle() method.

Shown elements are hidden and hidden elements are shown:

The optional speed parameter can take the following values: "slow", "fast", or milliseconds.

The optional callback parameter is a function to be executed after toggle() completes.

Syntax:

$(selector).toggle(speed,callback);

Example

<!DOCTYPE html>  
<html lang="en">  
<head>  
  <meta charset="utf-8">  
  <title>toogle() jQuery Method</title>  
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <style>  
  	h2 {  
    	color: white;  
        text-align:center;
        padding-top:40px;
  	}  
  </style>  
<script type="text/javascript">
$(document).ready(function(){
  $("#button").click(function(){
     $("#div").toggle();
  });
});
</script> 
</head>  
<body>
<button id="button">Show/Hide</button>
<br>
<br>
<div id="div" style="width:400;height:100px;display:none;background-color:green;"><h2>STUDENTS TUTORIAL</h2></div>
 
</body>  
</html>

Run it Yourself »