jQuery toggle() method
Example
Toggle between slideUp() and slideDown() on all
Toggle between hiding and showing elements:
$
(
"
button
"
)
.
click
(
function
(
)
{
$
(
"
p
"
)
.
toggle
(
)
;
}
)
;
Try it »
Definition and Usage
The toggle() method toggles between hide() and show() on the selected elements. hide() and show() slideUp() and slideDown().
This method checks the visibility of the selected elements. If an element is hidden, show() runs; if an element is visible, hide() runs - creating a toggling effect.
**Note:** Hidden elements will not be fully displayed (they no longer affect the page's layout).
**Tip:** This method can be used to toggle between custom functions.
Syntax
$(
selector
).toggle(
speed,easing,callback
)
| Parameters | Description |
|---|---|
| speed | Optional. Specifies the speed of the hiding/showing effect.
Possible values: |
Possible values:
- "swing" - Moves slowly at the beginning/end, and faster in the middle
- "linear" - Moves at a constant speed
To learn more about callback, please visit our jQuery Callback chapter on callbacks.
|More examples
toggle() - Using the speed parameter
How to use the speed parameter to specify the speed of the hide/show effect.
toggle() - Using the callback parameter
How to use the callback parameter when toggling between hide/show effects.
jQuery effects methods