Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide/remove a DIV when empty

Tags:

jquery

css

I have some server side HTML output I cannot deal with using pure CSS, essentially the DIV sometimes holds:

<div><span>Content</span></div>

or

<div><p>Content</p></div>

or

<div>Content</div>

or

<div> </div>

When the DIV == <div> </div> I want to remove it.

Any ideas?

like image 953
CLiown Avatar asked Sep 21 '09 15:09

CLiown


People also ask

How do you hide a div if it is empty?

Hide empty divs - To hide the div set: display: none; in :empty selector · GitHub.

How do I hide a specific div?

To hide an element, set the style display property to “none”. document. getElementById("element").

How would you hide the element while still maintaining the element space?

You can hide an element in CSS using the CSS properties display: none or visibility: hidden . display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.

Can you disable a whole div?

Nope! Divs can't be disabled. Only form and form elems. Actually in Quirks-mode IE can disable a div , but it only grays button texts, it doesn't prevent events firing.


1 Answers

You can do this using only CSS:

div:empty { display: none }
like image 98
Andrew Avatar answered Sep 21 '22 08:09

Andrew