Home >>jQuery Tutorial >jQuery slideToggle() Method

jQuery slideToggle() Method

jQuery slideToggle() Method

For the selected elements the jQuery slidetoggle() method is used to slideup()and slidedown().

This method searches for visibility on selected components. SlideDown() is executed if it hides an item. SlideUp() is executed when an element is available-this produces a toggle.

Syntax:
$(selector).slideToggle(speed,easing,callback)

Parameter Values

Parameter Description
speed It is an optional parameter and is used to Specify the speed of the slide effect. Its default value is 400 milliseconds

Possible values:

  • milliseconds
  • "slow"
  • "fast"
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:

  • "swing" - faster in the middle, moves slower at the beginning
  • "linear" – it moves in a constant speed
callback It is an optional parameter. After the slideToggle() method is completed a function to be executed
Here is an Example of jQuery slideToggle() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$(".slidetoggle").slideToggle();
});
});
</script>
</head>
<body>
<p class="slidetoggle">Hello World !!!</p>
<button>Toggle slideUp() and slideDown()</button>
</body>
</html>

Output:

Hello World !!!


No Sidebar ads