Search code examples
jquery-uidroppablejquery-ui-droppablejquery-droppable

jquery-ui droppable: prevent parent from accepting children


I'm making a document list, and I need to stop a draggable element being accepted by its parent. The option is set like:

$( ".onedoc" ).droppable({
accept: ".onedoc"
});

but I want the droppable not to accept its immediate children. The problem is since it's a nested list, the parents and children have the same classes, so I need to do something like

accept: $(".onedoc").not($(this).children())

but of course this doesn't work.


Solution

  • Maybe because accept: is looking for a selector and your are providing it with a jQuery object?

    How about you provide it with a function?

    $(".onedoc").droppable({
        accept: function (elem) {
            // check elem here for being a child and return false
            return !$(this).has(elem).length;
        }
    });