0

I want to delete all the divs who has at least one child using jquery. So for this example I need to delete the divs containing paragraph with 'hello' and 'world'. Can any one please help ?

<div style="background:#FF0000;height:200px;width:200px;">
<p> Hello </p>
</div>
<div style="background:#00FF00;height:200px;width:200px; ">
</div>
<div style="background:#0000FF;height:200px;width:200px;">
</div>
<div style="background:#AAAA3A;height:200px;width:200px;">
<p>World </p>
</div>
4

2 回答 2

1

Try the :has selector

$('div:has(*)').remove();

http://jsfiddle.net/9GdmN/

于 2013-05-13T03:25:03.143 回答
0
$('div').each(function () {
    if ($(this).children().length > 0) $(this).remove();
});

jsFiddle example

于 2013-05-13T03:25:45.677 回答