Jquery droppable get draggable id

22,962

Solution 1

As they says in jQuery UI dropable doc

All callbacks receive two arguments: The original browser event and a prepared ui object, view below for a documentation of this object (if you name your second argument 'ui'):

ui.draggable - current draggable element, a jQuery object.
ui.helper - current draggable helper, a jQuery object
ui.position - current position of the draggable helper { top: , left: }
ui.offset - current absolute position of the draggable helper { top: , left: }

ui.draggable is the element being dropped as a jQuery object.

So You can get the ID using ui.draggable.prop('id')

Solution 2

You can use ui.draggable to address draggable element.

drop: function(event, ui) {
    var id = ui.draggable.attr("id");
}

DEMO: http://jsfiddle.net/9RBJG/

Share:
22,962
Akshay
Author by

Akshay

Updated on March 12, 2020

Comments

  • Akshay
    Akshay about 4 years

    I want to get dragged id when i dropped to the certain div

      Drag  <ul id="demo" > 
             <li id="1" ></li>
             <li id="2" ></li>
            <li id="3" ></li>
            </ul>
    
             <div class="drop"> drop here!! </div>
    

    JQUERY

      $(".drop").droppable({ 
                    drop: function(event, ui) {
    
          // i need to get dragged id (note:able to  drag multiple ids)
    
            1,2,3..     
    
                }       
                });
    

    Please help me out!! Thnks