Possible Duplicate:
How to move an element into another element?
I basically want to reassign a parent to my DIV:
<DIV id='main'>
<DIV id='child'>
</DIV>
</DIV>
<DIV id='surrogate'>
</DIV>
So i want child to be child of surrogate.
I tried:
var $a = $('#child');
var contents = $a.contents();
$a.remove();
$('#surrogate').append('<p>' + contents + '</p>');
But it will just output: [object Object]
Is there a better/working way to just reassign a parent to a whole tree of elements, without reading the content copying or cloning it? Well, maybe cloning works, but I'd rather just move it.
` that will get wrapped with another `
` when you append it to the surrogate div (i.e., `$a.html() == '
Old content of child div.
';`). – msanford Mar 07 '12 at 20:07