.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().
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$(".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
Call
What it does
.toggle()
Learn jQuery .toggle(): flip element visibility instantly or with animation, boolean show/hide since 1.3, toggle vs show vs hide, durations, callbacks, examples, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Select the element(s) to toggle.
Step 2
Call .toggle() for an instant flip, or pass a duration / options.
Step 3
Or pass true / false to force show / hide (jQuery 1.3+).
Return Value
Return Value
Description
Boolean
Often true or false depending on the match or state.
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
Example 1 — Instant Toggle
Flip paragraph visibility immediately with no animation.
Boolean. Since 1.3, a Boolean skips the visibility check.
true. Calls the same path as .show().
false. Calls the same path as .hide().
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.