6

When I drop something to jquery droppable, I want to get the dropped items' id. When I did it like this:

$("#here").droppable({
        tolerance: 'fit',
        accept: ".one",
         drop: function(){
            id = $(this).attr("id");
            alert (id);
        }
    });

it of course alerted the id of the droppable here. How can I select the id of the dropped div?

Logan
  • 10,649
  • 13
  • 41
  • 54

2 Answers2

7

Change your drop function to take two arguments: event, ui

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

The draggable that is being dropped is represented by ui.draggable

Found in the jquery ui docs for droppable.

joekarl
  • 2,118
  • 14
  • 23
  • thanks! I was wondering why it didn't work when i did it like `tasid = $(ui.draggable).attr("id");`... forgot `(event,ui)` – Logan Jun 08 '11 at 06:40
3

This worked for me:

   $( "#droppable" ).droppable({
          drop: function( event, ui ) {
                var draggableId = ui.draggable.attr("id");
            var droppableId = $(this).attr("id");
          }
        });
      });
Arijit
  • 1,633
  • 2
  • 21
  • 35