jQuery toggle()

toggle() switches matched elements between shown and hidden states. It is useful when the same control should alternate visibility each time it is activated.

toggle() Syntax Top ↑

$("#d1").toggle();

Toggle on a Click Top ↑

$("#b1").on("click", function () {
    $("#d1").toggle();
});

Demo: toggle an element →

Control the Transition Speed Top ↑

Like show() and hide(), toggle() can animate the change when you pass a duration.

$("#d1").toggle("fast");
$("#d1").toggle(600);

Demo: toggle with different durations →

If you want the transition to change opacity instead of using the show/hide animation, use fadeToggle(). For vertical expanding and collapsing, use slideToggle().

← Previous: show() / hide() · jQuery Effects · Next: fadeIn() / fadeOut() →






plus2net.com






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer