.slideToggle() (since jQuery 1.0) displays or hides matched elements with a sliding motion by animating height. Visible elements slide up and get display: none; hidden elements slide down and show. Returns the jQuery object for chaining.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$("#panel").slideToggle(); // default 400 ms
$("#panel").slideToggle("slow"); // 600 ms
$("#panel").slideToggle(600, "linear", function () { /* done */ });
// Visible → slide up → display:none
// Hidden → slide down → fully visible
// display is saved and restored (e.g. inline stays inline)
Call
What it does
.slideToggle()
Learn jQuery .slideToggle(): show or hide matched elements with a sliding height animation since 1.0, duration presets, easing since 1.4.3, per-element callbacks, and compare with slideDown, slideUp, fadeToggle, and .toggle().
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Select the target with jQuery ($("#panel")).
Step 2
On a user action, call .slideToggle() (optional duration / easing / complete).
Step 3
jQuery checks visibility and runs slide-up or slide-down.
Return Value
Return Value
Description
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
Example 1 — Slow Toggle on Click
Official pattern: element starts shown; each click slides it closed or open.
jQuery
$("#clickme").on("click", function () {
$("#book").slideToggle("slow", function () {
// Animation complete.
});
});
Each click toggles all paragraphs
Visible ones collapse; hidden ones expand
All run in parallel over 600 ms
How It Works
Set. Every matched p is toggled.
Per element. Direction comes from each paragraph’s own visibility.
Parallel. They animate together, not one after another.
Example 3 — Toggle with Per-Element Counter
Official idea: toggle several panels; increment a counter in each complete callback.
jQuery
$("#aa").on("click", function () {
$(".panel").slideToggle("slow", function () {
var n = parseInt($("#count").text(), 10);
$("#count").text(n + 1);
});
});
Panels slide up/down together
Counter +1 for each panel when its slide ends
Three panels → counter can jump by 3 per click
How It Works
Toggle set. All .panel elements animate.
Complete. Runs once per panel, not once for the group.
Count. Each finish increments the number.
Frequently Asked Questions
.slideToggle() shows or hides matched elements with a sliding motion by animating height. If the element is visible, it slides up and hides; if hidden, it slides down and shows. One call replaces a manual slideDown / slideUp branch.
1) .slideToggle([duration] [, complete]) — optional duration and completion callback. 2) .slideToggle(options) — an options object with duration, easing, queue, step, progress, and Promise-style callbacks. 3) .slideToggle([duration] [, easing] [, complete]) — positional easing since jQuery 1.4.3.
.slideDown() always reveals; .slideUp() always collapses. .fadeToggle() toggles opacity, not height. .toggle() switches display instantly with no animation. .slideToggle() picks slideDown or slideUp from current visibility.
Milliseconds, or the strings "fast" (200 ms) and "slow" (600 ms). Default is 400 ms when omitted.
Once per matched element when that element’s slide finishes — not once for the whole set. Use .promise().done() when you need a single callback after every element completes.
Yes. jQuery saves and restores display as needed. If an element was inline before hiding, it returns to inline after showing. When height reaches 0 after a hide, display is set to none so the element no longer affects layout.