Possible Duplicate:
Checking if an html element is empty with jQuery
I have an empty div like this:
<div id="cartContent"></div>
I need to check if it’s empty. If it’s empty it needs to return true and then some
elements are added. If not it returns false and some other function executes. What’s the best way to check if there are any
elements in the div?
Thanks
You can use native JavaScript:
You can use
.is():Or you could just test the
lengthproperty to see if one was found:You can use
$.trim()to remove whitespace (if that’s what you want) and check for the length of the content: