O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hiding and Showing Elements

$("#down").hide(); $("#up").on("click", function(){   $("#up, #down").toggle();   $("#leftNav").hide(); }); $("#down").on("click", function(){   $("#up, #down").toggle();   $("#leftNav").show(); });

A simple way of changing the look and feel of web pages is to toggle the visibility of elements. Hiding elements that are not necessary and then only showing them when they become necessary can save a lot of screen space that can be critical in a well-implemented web application.

You hide or show elements from JavaScript by setting the style.display property to "none" or to "". jQuery, in contrast, provides a much more elegant and extensible solution.

To display an element using jQuery, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required