I am trying to remove an element from the DOM if it does not contain any elements.
Here is what I tried:
var numChildren = 0;
$("#messages").children().each(function () {
numChildren += 1;
});
if (numChildren <= 0) {
$("#messages").slideUp("normal", function () { $(this).remove(); });
}
Don’t forget though that this will remove the
messagesdiv from the DOM.