views:

1493

answers:

2

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?

A: 

I would start with

if ($ ('#droptarget .widget')) {
  // do something
}
Ilya Birman
$('#droptarget .widget') would always return an object, hence evaluate to true. You'd want to check if ($('#droptarget .widget').length > 0)
Mario Menger
+3  A: 

If you want to select the outer div:

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

If you want to select the widget:

$("#droptarget > div.widget")
cletus
as simple as :has! thanks
Tom