The toggle() method is used to check the visibility of selected elements to toggle between hide() and show() for the selected elements.
- show() is run when the element is hidden.
- hide() is run when the element is visible.
$(selector).toggle(speed, easing, callback)
Parameters: It has three optional parameters:
- speed: It is used to specify the speed of the toggle effect. It can be in terms of milliseconds, slow or fast.
- easing: It is used to specify the speed of the element at the different points of animation.
- callback: The function to be immediately called after the toggle effect.
Below is the example to show the toggle() method:
Before clicking on the button:
After clicking on the button:
After clicking on the button again:
- How to create slide left and right toggle effect using jQuery?
- jQuery | Hide/Show, Toggle and Fading methods with Examples
- jQuery | die() Method
- jQuery | get() Method
- jQuery | off() Method
- jQuery | add() method with Example
- jQuery | is() Method
- jQuery | before() Method
- jQuery | ajaxSetup() Method
- jQuery | text() Method
- jQuery | live() Method
- jQuery | getJSON() Method
- jQuery | Misc each() Method
- jQuery | unload() Method
- jQuery | Misc get() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.