View Full Version : Duplicate a Div
Clayf700
12-11-2010, 04:29 AM
Okay, Let's Say I have a Div and a Dock/Table.
How would i make the div duplicate into a dock?
Pretty Much how would I duplicate things? and in a specific spot too by class name?
jscheuer1
12-11-2010, 06:57 AM
You haven't given much information. I can tell you that the way to duplicate something is to obtain a reference to it and then clone it, ex:
document.getElementById('test').cloneNode(true);
If you want to put the clone somewhere, you need to append it to something else that you have a reference to, ex:
document.getElementById('testTarget').appendChild(document.getElementById('test').cloneNode(true));
If you just want to move it, then don't clone it:
document.getElementById('testTarget').appendChild(document.getElementById('test'));
Appending an existing node moves it. One node cannot be in two places at once.
If you want to use class instead of id, it can get a little complicated depending upon how backward compatible you want it to be.
At that point I would suggest using jQuery. The code can be more succinct and backward compatibility is assured (for the most part).
If you want more help though, I would need to get a clearer idea what you're going for. So if you do want more help:
Please post a link to a page on your site that contains the problematic code so we can check it out.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.