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, ...

Get jQuery and JavaScript Phrasebook 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.