jQuery .fadeToggle() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Effects

Definition

.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
CallWhat 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

ParameterDescription
Step 1Select the target with jQuery ($("#panel")).
Step 2On a user action, call .fadeToggle() (optional duration / easing / complete).
Step 3jQuery checks visibility and runs fade-in or fade-out.

Return Value

Return ValueDescription
See examplesCheck 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 ");
  });
});
Try It Yourself

How It Works

  1. Target. Each button selects a different paragraph.
  2. Slow path. "slow" is 600 ms; "linear" keeps a steady pace.
  3. Fast path. "fast" is 200 ms with default swing easing.

Example 2 — Toggle a Panel on Click

One button, default 400 ms — jQuery picks fade-in or fade-out.

jQuery
$("#toggle").on("click", function () {
  $("#panel").fadeToggle();
});
Try It Yourself

How It Works

  1. Bind. The click handler always calls the same method.
  2. Inspect. jQuery reads whether #panel is visible.
  3. Animate. Visible → fade out; hidden → fade in.

Example 3 — Accordion (One Open)

Fade-toggle the clicked section; fadeOut other open panels first.

jQuery
$(".acc-head").on("click", function () {
  var $body = $(this).next(".acc-body");

  $(".acc-body").not($body).filter(":visible").fadeOut(300);
  $body.fadeToggle(300);
});
Try It Yourself

How It Works

  1. Sibling. .next(".acc-body") is the panel under the header.
  2. Close others. Visible siblings get .fadeOut(300).
  3. 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.

Next: .slideDown() Method

Reveal hidden content by animating height — the slide counterpart to fade effects.

.slideDown() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful