Sam
Sam

Reputation: 1514

Jquery draggable - move dragged element instead of duplicating

Can someone tell me how best to implement Jquery draggable and droppable so that the dragged element is MOVED to its new position?

Do you need to implement your own helper functions for this, or is it included in the Jquery plugin?

Upvotes: 2

Views: 3198

Answers (2)

JonK
JonK

Reputation: 622

You can also use clone:

pnlText.draggable({
    helper: "clone",
    stop: function(event, ui) {
        $(this).css("top",ui.position.top).css("left",ui.position.left);
    }
});

This pops the original to the location of the clone when the mouse is let go.

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630597

In the helper option is by default 'original' which will do exactly what you want, so just leave the option off, or set it to 'original' and you'll grab the original...as opposed to 'clone' which makes a copy. It should look like this:

$(".element").draggable(function() {
  helper: 'original' //or leave this line off
});

You can test it in the default demo here.

Upvotes: 6

Related Questions