views:

23

answers:

1

So I'm using the ui library, and I have something like:

$('#trash-bin').droppable({
        tolerance: 'touch',
        drop: function(event, ui) {
            alert(ui.draggable.id + " was dropped");
        }
    });
    $('#images').draggable({});

Which I know is wrong (the alert says "undefined dropped")

How can I reference the image's id that was dropped?

+2  A: 

It's stated in the documentations that the ui.draggable object is a jQuery object, not the original DOM element:

ui.draggable - current draggable element, a jQuery object.

http://jqueryui.com/demos/droppable/

So you'll have to use the attr function instead:

drop: function(event, ui) {
    alert(ui.draggable.attr('id') + " was dropped");
}
Yi Jiang