Hi guys Say I have one div including some text and images. Now I want to put this div inside another using dhtml. For example I can put a text inside a div using javascript like this: document.getElementById("myDiv").innerHTML = "hey body"; PHP: but the same wouldn't work if I want to put a whole object such as a div like this: document.getElementById("myDiv1").innerHTML = document.getElementById("myDiv2"); PHP: Do you think I have to use positioning or is there another way?
You have to consider factors such as whether you want to replace the contents every time you put a div inside the container div. If it's ok to just append every time, then try this simple example. <html> <head> <script type="text/javascript"> function moveIn(obj) { document.getElementById('d1').appendChild(obj); } </script> </head> <body> <div id="d1" style="border: 1px solid black; width: 50px; height: 50px;"></div> <div style="border: 1px solid black; width: 50px; height: 50px;"> <div id="d2" style="margin: 10px; border: 1px solid black; background-color: red; width: 10px; height: 10px;" onclick="moveIn(this);"></div> <div id="d3" style="margin: 10px; border: 1px solid black; background-color: blue; width: 10px; height: 10px;" onclick="moveIn(this);"></div> </div> </body> </html> Code (markup):