javimaravillas
javimaravillas

Reputation: 275

Get the item/object where the element is dropped

I'm coding a task panel with three lists and I use sortable to move item between them. But I need to pick up the item where the element is dropped. I know that ui.item is the element dropped, but I don't know where I dropped it. Here is my code:

$( ".column" ).sortable({
    receive: function(event, ui) {
        /* get the element where ui.item is dropped */
    }
});

I know that the element will be any with the .column selector, but how to pick!!!

Upvotes: 7

Views: 11148

Answers (2)

Alex Shuraits
Alex Shuraits

Reputation: 442

Very Simple:

alert($(this).attr('id')); //this is element where the item was dropped in 

Upvotes: 4

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76880

EDIT - a way to do that is like this

$("#sortable1, #sortable2").sortable({
    connectWith: ".connectedSortable",
    receive: function(e, ui) {
        alert(ui.item.closest('ul').attr('id'));

    }
}).disableSelection();

Of course if you wan't to get the element next to the dropped element you'd do

ui.item.closest('ul')

fiddle here http://jsfiddle.net/dKaYM/

Upvotes: 7

Related Questions