Martin Tóth
Martin Tóth

Reputation: 1747

jQuery draggable/droppable: access to original element

I'm dragging elements from one unordered list to another:

$('ul#drag li').draggable({ helper: 'clone' });
$('ul#drop').droppable({
    drop: function (event, ui) {
        ui.draggable.sourceElement.css(... ...);
    }
});

I want to mark already dragged elements in source list (but still allow dragging them), how do I access them through jQuery chain?

I guess I can set id attribute on the dragged element, and when dropping, the cloned element would have the same id, which I can use in finding the original, but I'm sure there's a nicer solution.


Upvotes: 5

Views: 5794

Answers (2)

George
George

Reputation: 4413

e.target refers to the original element

Upvotes: 6

Martin Tóth
Martin Tóth

Reputation: 1747

I wonder why I did not notice that the following works, the first time I tried it:

ui.draggable.css('whatever');

It's even documented:

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

Upvotes: 6

Related Questions