I have some server side HTML output I cannot deal with using pure CSS, essentially the DIV sometimes holds:
Content
You can do this using only CSS:
div:empty { display: none }
You can also use CSS-only to solve this, putting a table with style="empty-cells:hide"
around the content, and changing the div
to a td
, like this:
Before:
<div>Content</div>
After:
<table style="empty-cells:hide"><tr><td>Content</td></tr></table>
Here's another easy way... using the filter()...
$('div').filter(function() {
return $.trim($(this).text()) === ''
}).remove()
Even better (assuming jQuery):
$(document).ready(function() { $('div:empty').remove(); });
EDIT: The other answers are good, but the OP wanted to remove the empty item, not hide it.
I think you can do the following:
$(function() {
$("div:empty").hide();
});
jQuery's empty pseudo selector is great.