Node.cloneNode()메서드는 이 메서드를 호출한 Node 의 복제된 Node를 반환합니다.
var dupNode = node.cloneNode(deep);
복제되어야 할 node.
복제된 새로운 node.
- deep Optional
해당 node의 children 까지 복제하려면 true, 해당 node 만 복제하려면 false
var p = document.getElementById("para1"); var p_prime = p.cloneNode(true);
Cloning a node copies all of its attributes and their values, including intrinsic (in–line) listeners. It does not copy event listeners added using
addEventListener() (en-US) or those assigned to element properties. (e.g.
node.onclick = fn) Moreover, for a <canvas> element, the painted image is not copied.
The duplicate node returned by
cloneNode() is not part of the document until it is added to another node that is part of the document using
Node.appendChild() or a similar method. It also has no parent until it is appended to another node.
deep is set to
false, child nodes are not cloned. Any text that the node contains is not cloned either, as it is contained in one or more child
deep evaluates to
true, the whole subtree (including text that may be in child
Text nodes) is copied too. For empty nodes (e.g.
<input> elements) it doesn't matter whether
deep is set to
cloneNode() may lead to duplicate element IDs in a document.
If the original node has an ID and the clone is to be placed in the same document, the ID of the clone should be modified to be unique. Name attributes may need to be modified also, depending on whether duplicate names are expected.
To clone a node for appending to a different document, use
|DOM Standard |
BCD tables only load in the browser