Copy a <li> element from one list to another:
Before cloning:
After cloning:
More "Try it Yourself" examples below.
The cloneNode() method creates a copy of a node, and returns the clone.
The cloneNode() method clones all attributes and their values.
Tip: Use the appendChild() or insertBefore() method to insert the cloned node to the document.
Tip: Set the deep parameter value to true if you want to clone all descendants (children), otherwise false.
Method | |||||
---|---|---|---|---|---|
cloneNode() | Yes | Yes | Yes | Yes | Yes |
Parameter | Type | Description |
---|---|---|
deep | Boolean |
Optional. Specifies whether all descendants of the node should be cloned.
|
Return Value: | A Node object, representing the cloned node |
---|---|
DOM Version | Core Level 1 Node Object |
Copy a <div> element, including all its attributes and child elements, and append it to the document:
HTML DOM reference: document.adoptNode() Method
HTML DOM reference: document.importNode() Method
HTML DOM reference: document.createElement() Method
HTML DOM reference: document.createTextNode() Method