code_pretty
code_pretty

Reputation: 145

How to get id of droppable in draggable?

I looking for solution to my issue . Is there in jQuery UI in Draggable possibility to check for which element of DOM the object is dragged ?

I know there is no problem if we are talking about droppable, here we have option to get dragged element id, but what in other case ?

I need to restrict drag and drop in arrays of booleans. So when element is dragged into droggable I would like to check if boolean is true or false on this particular droppable.

Thanks in advance

Upvotes: 0

Views: 625

Answers (1)

akhikhl
akhikhl

Reputation: 2578

Here is the solution for your problem:

You need to pass "accept" parameter to the droppable on the page, like this:

$("#droppable").droppable({
    accept: function (source) {
        // return true, if droppable accepts given source (draggable)
        return $(source).attr('id') == 'draggable'
    },
    drop: function (event, ui) {
        // here $(this) is droppable where the drop occured.
        $(this).html("Dropped!");
    }
});

The complete working example here: http://jsfiddle.net/akhikhl/3KaaH/1/

Upvotes: 3

Related Questions