检查div中是否包含jQuery中的元素

问题描述:

我在jQuery中拖放一些拖放小部件,一旦被删除,我需要检查我的拖放和拖放小部件是否在另一个div中。

I'm bulding some drag and drop widgets in jQuery, once they've been dropped I need to check if my drag and droppable widget are inside another div.

<div id="droptarget">
    <div class="widget">I'm a widget!</div>
</div>

我已经看过 $('#droptarget')。每个,但似乎无法弄清楚。任何想法?

I've had a look at $('#droptarget').each but can't seem to figure it out. Any ideas?

如果要选择外部div:

If you want to select the outer div:

$("#droptarget:has(div.widget)")

如果要选择该小部件:

$("#droptarget > div.widget")