This post will discuss how to hide a div container in JavaScript and jQuery.

1. Using jQuery

The most common approach to hide an element in jQuery is to use the .hide() method. It works by setting the display CSS property to none. Now the document is rendered as though the element did not exist.

Edit in JSFiddle

 
Alternatively, you can directly set the display CSS property to none by calling .css("display", "none").

Edit in JSFiddle

 
If you want to preserve the space taken by the element within the document, set the visibility property to hidden instead.

Edit in JSFiddle

 
Another approach is to use the .fadeOut() method to set the display style property to none. You can further add a delay with the .delay() method.

Edit in JSFiddle

 
Like .fadeOut() method, you can use the .slideUp() method to set the display style property to none.

Edit in JSFiddle

2. Using JavaScript

In plain JavaScript, you can set the CSS display property to none, as shown below:

Edit in JSFiddle

 
The display property hides the element and also removes it from the DOM. To avoid changing the document’s layout, you can set its visibility to hidden instead.

Edit in JSFiddle

That’s all about hiding a div container in JavaScript and jQuery.