Reputation: 25
I have tried to move my div and its contents to another div using such things as:
<script>
document.getElementById('#header').appendChild(
document.getElementById('#live')
);
</script>
and
<script>
$("#header").append($("#live"))
);
</script>
but i cant move the div the best i have done is move some text about.
Help.
Upvotes: 1
Views: 2391
Reputation: 2244
If you're using jQuery, the code you want is
$('#div1Content').appendTo('#div2');
Have a look here for a demo, http://jsfiddle.net/nwe44/we2cN/
Upvotes: 3
Reputation: 13853
Try
$('#live').appendTo('#header');
alternatively,
var live = $('#live').detach();
//do stuff
live.appendTo('#header');
detach() removes it from the DOM but keeps it in memory, then you can append it to its new parent.
Upvotes: 2
Reputation: 166001
With jQuery (as you appear to be using it in one of your examples) you can use the appendTo
method (see docs):
$("#live").appendTo("#header");
This moves the #live
element into the #header
element.
Upvotes: 0