Create two variables to store content:
var firstDivContent = document.getElementById('mydiv1');
var secondDivContent = document.getElementById('mydiv2');
Now just set the value in the second div:
secondDivContent.innerHTML = firstDivContent.innerHTML;
Complete code:
<html>
<head>
<script type="text/javascript">
function copyDiv(){
var firstDivContent = document.getElementById('mydiv1');
var secondDivContent = document.getElementById('mydiv2');
secondDivContent.innerHTML = firstDivContent.innerHTML;
}
</script>
</head>
<body onload="copyDiv();">
<div id="mydiv1">
<div id="div1">
</div>
<div id="div2">
</div>
</div>
<div id="mydiv2">
</div>
</body>
</html>
Demonstration http://jsfiddle.net/GCn8j/
Source: https://stackoverflow.com/questions/20173101/copy-the-content-of-a-div-into-another-div
That’s :D, what I wanted was this innerHTML. Very obg.
– Aj Garcia
I’m glad you decided :) has how to mark the answer as right? :)
– LeoCBS