English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The toggle() method inhide()andshow()Switch between methods.
This method checks the visibility of the selected element:
If the element was initially displayed, it will be hidden
If the element was initially hidden, it will be displayed
Note:Hidden elements will no longer affect the page layout.
$(selector).toggle(duration, easing, callback)
Toggle between hiding and showing all <p> elements when the button is clicked:
$("button").click(function(){ $("p").toggle(); });Test to see‹/›
UsedurationParameters:
$("button").click(function(){ $("p").toggle(1500); });Test to see‹/›
UsecallbackParameters:
$("button").click(function(){ $("div").toggle(1500, function(){ alert("toggle() effect completed!!!"); }); });Test to see‹/›
Create animations for all spans (for example, words) to quickly hide/Display, and in2Complete each animation within 00 milliseconds:
$("button").click(function(){ $("span:first-child").toggle("fast", function(){ $(this).next().toggle("fast", arguments.callee); }); });Test to see‹/›
Parameter | Description |
---|---|
duration | An optional value to determine the hiding/How long the display effect will run. The preset value is400 milliseconds Possible values:
|
easing | An optional string specifying the speed of the element at different points in the animation. The default value is "swing" Possible values:
|
callback | An optional function called after the toggle() method completes, called once for each selected element |