Using fadeToggle() for convenient state-checking logic

The fadeToggle() method exposed by jQuery will either fade an element in, or fade it out depending on the current state of the element. Elements that are visible will be faded out, while elements that are hidden will be faded in.

When elements are faded out with fadeToggle(), they will automatically be set to display:none at the end of the animation so that the element doesn't affect the layout of the page.

Get jQuery 1.4 Animation Techniques Beginner's Guide 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.