What is the slideToggle method in jQuery?

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.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources