Which method is used to clone a DOM node?
Analysis & Theory
`cloneNode()` creates a copy of the node it is called on.
What does `cloneNode(true)` do?
A
Clones only the node itself
B
Clones only the child nodes
C
Clones the node and all its descendants
D
Clones only text content
Analysis & Theory
`cloneNode(true)` performs a deep clone, including the element and all its children.
What does `cloneNode(false)` do?
A
Clones the node without any child nodes
B
Clones the entire document
Analysis & Theory
`cloneNode(false)` performs a shallow clone — only the element itself is copied, not its children.
Which of the following is **true** about cloned nodes?
A
They are automatically added to the DOM
B
They must be manually appended to appear in the DOM
C
They retain the same IDs as the original and must stay that way
D
They automatically update when the original does
Analysis & Theory
After cloning, you must append the new node manually to place it in the document.
What happens if you clone a node with an ID?
B
The clone gets a new unique ID
C
Both the original and clone have the same ID
D
It causes a browser crash
Analysis & Theory
Cloned nodes retain the same ID, which can cause duplicates unless you change it.
To avoid ID conflicts when cloning, what should you do?
A
Remove the ID after cloning
B
Change the ID using `setAttribute()` or `.id`
D
Use `cloneNode(false)` only
Analysis & Theory
Change the ID of the cloned node to maintain valid, unique identifiers in the DOM.
Can you clone a text node using `cloneNode()`?
Analysis & Theory
Any node, including text nodes, can be cloned using `cloneNode()`.
After cloning a node, which method inserts it into the DOM?
Analysis & Theory
Use `appendChild()` (or `prepend()` / `insertBefore()`) to place the cloned node into the DOM.
What does the following do? `let copy = original.cloneNode(true);`
A
It links `copy` and `original` so they mirror each other
B
It creates a deep copy of `original` and stores it in `copy`
D
It adds a duplicate to the DOM automatically
Analysis & Theory
`cloneNode(true)` creates a full, deep copy of `original`, stored in the variable `copy`.
What must be done to make a clone visible on the page?
B
Set `clone.visible = true`
C
Append it to a visible element using `appendChild()`
Analysis & Theory
A clone only becomes part of the visible DOM when it is appended to an existing node.