.fadeToggle() (since jQuery 1.4.4) displays or hides matched elements by animating their opacity. Visible elements fade out and get display: none; hidden elements unhide and fade in. Returns the jQuery object for chaining.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$("#panel").fadeToggle(); // default 400 ms
$("#panel").fadeToggle("slow", "linear");
$("#panel").fadeToggle("fast", function () { /* done */ });
// Visible → fade out → display:none
// Hidden → show → fade in to opacity 1
Call
What it does
.fadeToggle()
Learn jQuery .fadeToggle(): show or hide matched elements by animating opacity since 1.4.4, duration and easing defaults, per-element callbacks, options object, stop() for rapid clicks, and compare with fadeIn, fadeOut, .toggle(), and slideToggle.
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 .fadeToggle() (optional duration / easing / complete).
Step 3
jQuery checks visibility and runs fade-in or fade-out.
Return Value
Return Value
Description
See examples
Check the examples below for what this API returns in common cases.
jQuery Examples
Example 1 — Official Two-Button Demo
From the jQuery docs: slow linear on the first p; fast with a complete log on the last p.
jQuery
$("button").first().on("click", function () {
$("p").first().fadeToggle("slow", "linear");
});
$("button").last().on("click", function () {
$("p").last().fadeToggle("fast", function () {
$("#log").append(" finished ");
});
});
Click Section B → A fades out (if open)
B fades in (or out if it was already open)
Only one section stays visible
How It Works
Sibling..next(".acc-body") is the panel under the header.
Close others. Visible siblings get .fadeOut(300).
Toggle self..fadeToggle(300) opens or closes the clicked panel.
Frequently Asked Questions
.fadeToggle() shows or hides matched elements by animating opacity. If the element is visible, it fades out and sets display:none when opacity reaches 0. If hidden, it unhides and fades in to full opacity. One call replaces a manual fadeIn / fadeOut branch.
.fadeToggle() was added in jQuery 1.4.4. It shares the same duration defaults, easing support, and callback semantics as .fadeIn() and .fadeOut().
1) .fadeToggle([duration] [, easing] [, complete]) — optional duration (default 400 ms), easing (default swing), and a per-element complete callback. 2) .fadeToggle(options) — a plain object with duration, easing, queue, step, progress, complete, and Promise-style start/done/fail/always.
.fadeToggle() picks fade-in or fade-out from current visibility. .fadeIn() / .fadeOut() are one-direction only. .toggle() shows or hides instantly with no opacity animation. Use .fadeToggle() when one control should animate both directions.
Once per matched element when that element’s fade finishes — not once for the whole set. Inside the callback, this is the DOM element. Use .promise().done() when you need a single callback after every element completes.
Call .stop(true, true) before .fadeToggle(). The first true clears the fx queue; the second jumps the current animation to its end state. Then fadeToggle starts from a clean baseline.