jquery-tutorialsmade

Hide and show a DIV – jQuery toggle() methods!

It is very simple to hide and show a div with the help of show() and hide() jQuery functions, almost all of us know these functions.

To hide and show a div, a beginner would write a script like below:

If you see the above snippet, there are too many lines of code and the toggle works only if you have two buttons!!

But there are other plenty of ways you can toggle a div with these jQuery functions: toggle(), slideToggle() and fadeToggle()

Lets write an examples:

toggle() jQuery example without any animation:

If you want to add some animation effect then you can use either slideToggle() or fadeToggle().

Just replace the above jQuery part with this:

To see the fade animation replace the below code:

 

Related Posts

Leave a Reply