Matthew
Matthew

Reputation: 15642

jquery - referencing a jquery object

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?

Upvotes: 2

Views: 76

Answers (1)

Yi Jiang
Yi Jiang

Reputation: 50095

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");
}

Upvotes: 2

Related Questions