Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery toggle() method

jQuery toggle() method

jQuery effects methods jQuery effects methods

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:

  • Millisecond
  • "slow"
  • "fast"
  • | | *easing* | Optional. Specifies the speed of the element at different points in the animation. The default is "swing".

    Possible values:

    **Tip:** More easing functions are available in extension plugins. | | *callback* | Optional. A function to be executed after the toggle() method finishes.

    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 jQuery effects methods