Categories
JavaScript Answers

How to show or hide ‘div’ using JavaScript?

Spread the love

To show or hide ‘div’ using JavaScript, we set the div’s style.display property.

For instance, we write

element.style.display = "none";

to hide the element by setting element.style.display to 'none'.

We write

element.style.display = "block";

To show the element as a block element by setting element.style.display to 'block'.

Or we write

element.style.display = "inline";

To show the element as an inline element by setting element.style.display to 'inline'.

Or we write

element.style.display = "inline-block";

To show the element as an inline block element by setting element.style.display to 'inline-block'.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *