Toggling effects

Many of the jQuery effects have opposing functions, such as hide() and show() and fadeIn() and fadeOut(). So far, the recipes in this chapter have handled each of these functions separately; for example, one button to show and another to hide. For some of these functions, jQuery provides us with the ability to be able to toggle these opposing effects. This is beneficial because we do not need to deal with each case separately or decide which of the two we need to use. This recipe will look at the toggle functions and show you how they can be used.

Getting ready

In your favorite text editor or IDE, create a blank HTML file named recipe-4.html and save it in the same directory as your jQuery library.

How to do it…

  1. Add the following ...

Get jQuery 2.0 Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.