Serhat Ozgel
Serhat Ozgel

Reputation: 23766

How to get container of draggable inside drop event?

I have an html like this:

<div id="container1">
    <div class="dragme">drag me</div>
</div>
<div id="container2">
    <div class="dragme">drag me</div>
</div>
<div id="droponme"></div>

$(".dragme").draggable();
$("#droponme").droppable({
    accept: ".dragme",
    drop: function(e, u) { alert( /* find id of the container here*/ ); };
});

I want to find the container of the draggable object on drop event handler. How can I do this?

Upvotes: 1

Views: 1568

Answers (2)

user2675708
user2675708

Reputation: 1

It's another form to get droppable container:

$(".dragme").draggable();
$("#droponme").droppable({
    accept: ".dragme",
    drop: function(e, u) {
        alert(e.toElement);
    }
});

Upvotes: 0

Owen
Owen

Reputation: 84503

$(".dragme").draggable();
$("#droponme").droppable({
    accept: ".dragme",
    drop: function(e, u) {
        alert(u.draggable.parent().attr('id') );
        // in your example: container1 or container2
    }
});

Upvotes: 2

Related Questions