Home >>jQuery Tutorial >jQuery toggle() Method
jQuery toggle() method in jQuery is used to toggles between hide() and show() for the selected elements.
This method searches for visibility on selected components. Show() executes when the element is hidden. Hide() is executed when an element is available-this generates a toggle.
Syntax:$(selector).toggle(speed,easing,callback)
Parameter | Description |
---|---|
speed | It is an optional parameter and is used to Specify the speed of the hide/show effect.
Possible values:
|
easing | It is an optional parameter and is Specify the speed of the element in points of the animation. Its Default value is "swing"
Possible values:
|
callback | It is an optional parameter. After the toggle() method is completed a function to be executed |
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn").click(function(){
$(".toggle").toggle();
});
});
</script>
</head>
<body>
<h3 class="toggle">Phptpoint</h3>
<button class="btn">Toggle</button>
</body>
</html>