Cameron
Cameron

Reputation: 28783

jQuery UI: pass id of element dragged and dropped to a function

I have a function called saveSmilies which accepts two parameters: the dragged element id and the dropped element id.

I'm trying to do this like:

$('.draggable').draggable({
                    revert: true,
                    drop: function() {
                        $dropped = $(this);
                    },
                    stop: function() {
                        quiz1.saveSmilies($(this).attr('id'), $dropped);
                    }
                });

But it doesn't work... Am I doing this completely wrong? Or just a typo somewhere?

So basically If I dragged an element with an id of 'box1' and dropped it on an element with an id of 'box2' then it would do the following: quiz1.saveSmilies('box1','box2');

Upvotes: 1

Views: 254

Answers (1)

James Hill
James Hill

Reputation: 61793

This should work:

drop: function(ev, ui) {
    var draggedID = ui.draggable.attr("id");
    var droppedID = $(this).attr("id");
}

Upvotes: 1

Related Questions