检查div中是否包含jQuery中的元素 [英] check if div contains an element in jQuery
本文介绍了检查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")
这篇关于检查div中是否包含jQuery中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文