Search code examples
jqueryjquery-uijquery-ui-sortable

jquery ui sortable, get sending object


I have a two tables which items can sort/drop between both. In my beforeStop method I am trying to access the sender, the element the item has come form - but I am getting null.

http://api.jqueryui.com/sortable/#event-beforeStop

  $( "tbody" ).sortable({
            connectWith: "tbody",
            distance: 15,
            beforeStop: function(event, ui) {
                 console.log(ui.sender);

the console says

null

How can I get the element which the item has come from?


Solution

  • You can keep the source container in a variable on the start event.

    jsFiddle Demo

    var startElement = null;
    
    $("#sortable").sortable(
        {
            start: function (event, ui) {
                startElement = $(this)
            },
            beforeStop: function(event, ui) {
                console.log(startElement);
            },
            connectWith: "#sortable2"
        }
    );