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(); });
}
var messages = $('#messages');
if (messages.children().length < 1) {
messages.slideUp('normal', function () { $(this).remove(); });
}
Don't forget though that this will remove the messages
div from the DOM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With