drag me

How do I get the container being dragged inside the drop event?

I have 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 dropped object in the drop event handler. How can i do this?

+1


source to share


2 answers


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

      



+2


source


This is another form for getting a replaceable container:



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

      

0


source







All Articles