If you need a quick demonstration of how you check for empty divs, I suggest you try this link:
http://html-tuts.com/check-if-html-element-is-empty-or-has-children-tags/
The following are short examples:
CSS usage
If your div is empty without any white spaces, you can use CSS:
.someDiv:empty { display: none; }
Unfortunately, there is no CSS selector that selects the previous sibling element. Exists only for the following sibling element: x ~ y
.someDiv:empty ~ .anotherDiv { display: none; }
Using jQuery
Checking the text length of an element using the text () function
if ( $('#leftmenu').text().length == 0 ) { // length of text is 0 }
Check if the element has any child tags inside
if ( $('#leftmenu').children().length == 0 ) {
Check for empty elements if they have a space
if ( $.trim( $('.someDiv').text() ).length == 0 ) {
Dan Mar 30 '15 at 19:00 2015-03-30 19:00
source share