0

jquery を使用して、少なくとも 1 つの子を持つすべての div を削除したいと考えています。したがって、この例では、「hello」と「world」を含む段落を含む div を削除する必要があります。誰でも助けてもらえますか?

<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

:hasセレクターを試す

$('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 の例

于 2013-05-13T03:25:45.677 に答える