Alex Rivera | Logout

How to check if div element is empty

Asked 2013-01-26T09:48:49.870
34

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

Edit
Report

1 Answer

1
if ($("#cartContent").children().length == 0) 
{
     // no child
}
answered 2013-01-26T09:52:13.020

Your Answer