Created
December 13, 2012 02:55
-
-
Save rafaellyra/4273649 to your computer and use it in GitHub Desktop.
How to clone a dom element using native javascript I needed to clone a dom element in a project and have searched this at google and stackoverflow but i just finded a lot of big functions to do this, looking at jsref I findend the cloneNode method, a native javascript method to clone dom elements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Syntax | |
var dupNode = node.cloneNode(deep); | |
/* | |
node -> The node to be cloned. | |
dupNode -> The new node that will be a clone of node | |
deep (Optional) -> | |
[true] if the children of the node should also be cloned, or [ | |
false] to clone only the specified node. | |
*/ | |
//Example | |
var p = document.getElementById("para1"), | |
p_prime = p.cloneNode(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment