You may want to use the appendTo function (which adds to the end of the element):
$(“#source”).appendTo(“#destination”);
Alternatively you could use the prependTo function (which adds to the beginning of the element):
$(“#source”).prependTo(“#destination”);
Example:
$(“#appendTo”).click(function() {
$(“#moveMeIntoMain”).appendTo($(“#main”));
});
$(“#prependTo”).click(function() {
$(“#moveMeIntoMain”).prependTo($(“#main”));
});
#main {
border: 2px solid blue;
min-height: 100px;
}
.moveMeIntoMain {
border: 1px solid red;
}
my solution:
MOVE:
jQuery(“#NodesToMove”).detach().appendTo(‘#DestinationContainerNode’)
COPY:
jQuery(“#NodesToMove”).appendTo(‘#DestinationContainerNode’)
Note the usage of .detach(). When copying, be careful that you are not duplicating IDs.