Ask Your Question
0

How can I clone the main draggable element using jQuery UI and also make the cloned version draggable?

asked 2022-05-05 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-09-29 19:00:00 +0000

lalupa gravatar image

You can use the jQuery clone() method to clone the main draggable element and then initialize the cloned version as draggable using the jQuery UI draggable() method as follows:

// Clone the main draggable element
var $clonedElement = $('#main-draggable').clone();

// Make the cloned element draggable
$clonedElement.draggable();

// Append the cloned element to the container
$('#container').append($clonedElement);

Note that you should give the cloned element a new ID or class, otherwise you'll end up with multiple elements with the same ID, which is invalid HTML.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-05 11:00:00 +0000

Seen: 12 times

Last updated: Sep 29 '22