Web APIs
Node.cloneNode()
cloneNode(true) copies the subtree; cloneNode(false) copies the node without its children. Listeners registered through addEventListener are not copied. Check IDs before inserting a clone.
Formal Syntax & Structure
javascript syntaxjavascript
node.cloneNode([deep])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| deep | boolean | Include descendants when true. |
Return Value
Node
Cloned node.
Working Example
Example Snippetjavascript
const a=document.createElement("div");a.append(document.createElement("span"));const b=a.cloneNode(true),c=a.cloneNode(false);console.log(b.children.length,c.children.length,b===a);