Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
jquery
communitycreator

What is the slideToggle method in jQuery?

Chibuike Nwachukwu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In jQuery, the slideToggle() method is used to toggle an element by sliding it up or down, depending on the element’s current state.

If the element has been slid down, then the slideToggle() method slides it up to hide the contents.

If the element has been slid up, then the slideToggle() method slides it down to reveal the hidden content.

Syntax

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

Parameters

  • selector: The element to be acted upon.
  • speed: An optional parameter used to specify the duration of the event; speed can be a value in milliseconds or either of “slow” and “fast”.
  • easing: An optional parameter used to specify the speed of the element at different points of the animation. easing can take values of “swing” or “linear”, with swing being the default value.
  • callback: An optional parameter for the callback function that gets called once the sliding is over.

Code

In the code below, the text "Platform like no other!" gets toggled once the Toggle Slide button is clicked.

RELATED TAGS

javascript
jquery
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring