check if div contains an element in jQuery
问题 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> I've had a look at $('#droptarget').each but can't seem to figure it out. Any ideas? 回答1: If you want to select the outer div: $("#droptarget:has(div.widget)") If you want to select the widget: $("#droptarget > div.widget") 回答2: I would start with if ($ ('#droptarget .widget')) {