.toggle() shows or hides matched elements by flipping their current visibility (since jQuery 1.0). Instant with no args; with a duration it becomes an animation. Display is saved and restored like .hide() / .show().
Remember
$(".target").toggle() // instant flip
$("p").toggle("slow") // 600ms animation
$("#box").toggle(true) // force show (1.3+)
$("#box").toggle(false) // force hide (1.3+)
$("#box").toggle(400, function () { // ms + complete
// this = current element
});
// "fast" = 200ms · default animated duration = 400ms
Select elements, then flip visibility instantly, with a duration, or to a forced Boolean state.
Select the element(s) to toggle.
Call .toggle() for an instant flip, or pass a duration / options.
Or pass true / false to force show / hide (jQuery 1.3+).
Optionally pass a complete callback (runs once per element).
Piece
Required?
Role
Matched set
Yes
Elements to flip
duration
Optional
ms, "slow", or "fast"
display
Optional
true show · false hide (1.3+)
easing
Optional
"swing" or "linear" (1.4.3+)
complete
Optional
Runs after each element finishes
Pseudocode
Pseudocode
for each matched element el:
if argument is Boolean:
if true → show(el) // same as .show()
if false → hide(el) // same as .hide()
continue
if el is currently visible:
hide(el) // save display → none
else:
show(el) // restore saved display
if duration provided:
animate width, height, opacity during the flip
call complete(this = el) once per element
return original matched set
Reference
Cheat Sheet
Keep these facts handy while flipping visibility.
Topic
Detail
Instant
.toggle()
Animated
.toggle(duration[, easing][, complete])
Boolean
.toggle(true) / .toggle(false) (1.3+)
Since
jQuery 1.0 (Boolean 1.3 · easing 1.4.3)
Durations
"fast" 200 · default 400 · "slow" 600
Display
Saved and restored like hide / show
DOM
Element stays; layout space comes and goes
Global off
jQuery.fx.off = true
Try it
Live Preview
Flip the sample box instantly, slowly, or force show / hide.
Browser demo of .toggle() — same idea as the examples below.
Hello — I am the target box.
Result
$("#box").toggle()
→ flips current visibility
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Instant Toggle
Flip paragraph visibility immediately with no animation.
Each click flips paragraph visibility
Same idea as the official jQuery demo
How It Works
Bind..on("click") listens on the button.
Toggle. Each click flips every <p>.
No if/else. You do not need separate show and hide branches.
Pattern. Matches the official jQuery .toggle() click demo.
Edge Cases & Pitfalls
Check these before wiring toggle into real UIs.
name
Not the old event-handler .toggle()
Alternating click handlers were removed in 1.9. This method only flips visibility (or forces Boolean state).
queue
Instant toggle skips the queue
No duration (or 0) runs immediately and can override queued animations.
a11y
Update ARIA when toggling panels
Pair with aria-expanded / focus management on menus and dialogs so assistive tech stays in sync.
fx
jQuery.fx.off forces instant
When effects are off globally, animated .toggle() becomes duration 0 — plan for that in tests.
Compatibility
Browser Support
.toggle() has been part of jQuery since 1.0. Boolean display arrived in 1.3; the easing argument in 1.4.3. It works wherever your loaded jQuery version runs.
✓ Stable · jQuery 1.0+
jQuery .toggle()
Supported in all browsers that run jQuery 1.0+. Prefer a current jQuery 3.x build for modern projects.
100%jQuery core method
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.toggle()Universal
Bottom line: Safe for everyday UI. Prefer instant toggle for large sets; animate only when motion helps understanding.
Analysis
Performance Notes
Approach
Cost
Best for
.toggle() instant
Cheap
Bulk flip, tables, lists
.toggle("slow")
Layout + paint
Single panels, feedback
Many animated toggles
Expensive
Avoid — toggle one container instead
Instant toggle is fine at scale. Animated toggle on dozens of nodes can jank — animate one container instead of every child.
Remember
Key Takeaways
Role: flip visibility (or force show/hide with a Boolean).
Pair: built on the same display cache as .hide() / .show().
Animate: pass duration / "slow" / "fast".
Not events: the old click-handler .toggle() is gone since 1.9.
One line:.toggle() is the jQuery one-liner for on/off visibility without writing show/hide branches.
Frequently Asked Questions
.toggle() flips visibility of matched elements. Visible ones are hidden; hidden ones are shown. With no arguments the flip is instant. jQuery saves and restores display like .hide() and .show(). Returns the jQuery collection for chaining. Available since jQuery 1.0.
.show() always reveals; .hide() always hides. .toggle() checks current visibility and does the opposite — one call for on/off buttons, menus, and panels.
Since jQuery 1.3, a Boolean forces state: .toggle(true) shows (like .show()), .toggle(false) hides (like .hide()). Useful when you already know the desired state.
Yes. Pass a duration in ms, or "slow" (600) / "fast" (200). jQuery animates width, height, and opacity while flipping visibility. You can also pass easing, an options object, or a complete callback.
No. jQuery also had .toggle(handlerA, handlerB) for alternating click handlers — removed in jQuery 1.9. This page covers visibility .toggle(). For alternating handlers, use .on("click") with your own state flag.
Set jQuery.fx.off = true. All effects, including .toggle(), run with zero duration. Useful for tests or reduced motion.
Once per matched element when that element’s animation finishes — not once for the whole set.