[ACCEPTED]-Using jquery how can I remove a DIV if it's contents are empty?-jquery

Accepted answer
Score: 10

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')) { 

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. ;-)



Yes, as 1 per your commment, you can also do this



Score: 3

To remove the element with id equal to removeme:


To 3 remove the element with id equal to removeme only 2 if it is empty:


To remove all empty <div>s:


EDIT: If 1 it's not empty, but has whitespace:

if($.trim($("#removeme").text()) == "") {

Reference: Use jquery to remove a div with no children

More Related questions