This post will discuss how to change an element’s display to none or block using JavaScript and jQuery.

1. Using JavaScript

In pure JavaScript, you can control the rendering of the container elements using the display attribute. Setting the display to none will not render the element or any of its children, and setting it to block, the browser will render the element.

JS


CSS


HTML



Edit in JSFiddle

2. Using jQuery

In jQuery, you can use the .hide() and .show() methods to hide or show an element. This is demonstrated below:

Edit in JSFiddle

 
Alternatively, you can use the .css() method to modify the display attribute, which controls the rendering of container elements.

Edit in JSFiddle

That’s all about changing the element’s display to none or block using JavaScript and jQuery.