The slideToggle() Method in jQuery is used to show the hidden elements or hide the visible elements respectively i.e. it toggles between the slideUp() and slideDown() methods.
- slideDown() is run when the element is hidden.
- slideUp() is run when the element is visible.
$(selector).slideToggle()( speed, easing, callback )
Parameters: This method accepts three parameter as mentioned above and described below:
- Speed: It is an optional parameter and used to specify the speed of the fading effect. The default value of speed is 400 millisecond. The possible value of speed are:
- easing: It is an optional parameter and used to specify the speed of element to different points of animation. The default value of easing is “swing”. The possible value of easing are:
- callback: It is optional parameter. The callback function is executed after slideToggle() method is completed.
Below example illustrates the slideToggle() method in jQuery:
Example: This example display or hide the element.
- Before click on the button:
- After single click on the button:
- After double click on the button:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.