[ACCEPTED]-Using jquery how can I remove a DIV if it's contents are empty?-jquery
This works, assuming you don't have other div.group_call_to_action_aside
that 5 you want to keep:
if ($('.group_call_to_action_aside').is(':empty')) {
$('.group_call_to_action_aside').remove();
}
Note: I've styled the div
, so 4 you can see a brief flash of it before the 3 js takes effect. but you won't see this 2 when you do it because the div
is empty. ;-)
http://jsfiddle.net/jasongennaro/L8dwn/
EDIT
Yes, as 1 per your commment, you can also do this
$('.group_call_to_action_aside:empty').remove();
To remove the element with id
equal to removeme
:
$("#removeme").remove();
To 3 remove the element with id
equal to removeme
only 2 if it is empty:
$("#removeme:empty").remove();
To remove all empty <div>
s:
$("div:empty").remove();
EDIT: If 1 it's not empty, but has whitespace:
if($.trim($("#removeme").text()) == "") {
$("#removeme").remove();
}
Reference: Use jquery to remove a div with no children
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.