Reputation: 10545
Suppose I have the following markup
<div id="test">
<div class="original">hi</div>
<div class="news"></div>
<div class="duplicate"></div>
</div>
Now I want to remove original
and paste it to duplicate
The result should look like this
<div id="test">
<div class="news"></div>
<div class="duplicate"><div class="original">hi</div></div>
</div>
I tried like this
var orig = $('.original');
orig.remove().clone(true).appendTo('.duplicate'); // but not working
Upvotes: 0
Views: 133
Reputation: 36794
appendTo()
will 'move' the element:
var $orig = $('.original');
$orig.appendTo('.duplicate');
Upvotes: 2
Reputation: 8065
Try this:
var original = $('.original');
var duplicate = $('.duplicate');
duplicate.append(original);
From Jquery API:
If an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved into the target (not cloned):
Demo here
Upvotes: 3