Search code examples
jquerysortables

Jquery Sortables last "dragged" item


Sorry, back agin

How can I get at the "last" sortable item. I am dragging from one list 2 another but I need/want to append the "length" to the last dragged item which may not be the last item in the "dropped" list - hope you understand.

some idea of code

    $j(function() {
        $j("#id_section_layout").sortable({
        connectWith: '.colunm,.layoutcolunm,#layoutbin',
        helper: 'clone',
        receive: function(event, ui) {
        $j("#id_section_layout .content_options").children().show();
        var val= $j("#id_section_layout .content_options").length;
// .. I want to append val to the LAST dragged/dropped item
//.. If I do this it is always to the "last" item in the list which may not be the last dragged item -
             $j("#id_section_layout .content_options").last().append(val);
//.. So is there a way to get the last dragged item?
        }
        });
});

Solution

  • Inside your receive handler you can use ui.item, there are several elements available off the ui object your function receives:

    • ui.helper - the current helper element (most often a clone of the item)
    • ui.position - current position of the helper
    • ui.offset - current absolute position of the helper
    • ui.item - the current dragged element
    • ui.placeholder - the placeholder (if you defined one)
    • ui.sender - the sortable where the item comes from (only exists if you move from one connected list to another)