DMIL
DMIL

Reputation: 703

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.

Upvotes: 1

Views: 1799

Answers (1)

U.P
U.P

Reputation: 7442

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;
    }
});

Upvotes: 4

Related Questions