Cloning elements
Hey ,
I'm thrilled to help you learn JavaScript. Unfortunately, you've landed on a page where you cannot access with your current purchase.
Please upgrade (use this link) access this content.
I'm super eager to help you learn more!
Cloning elements
JavaScript lets you clone an element with cloneNode
.
const clone = element.cloneNode()
This clones the element (without including its children).
If you want to clone the children elements as well, you can pass true
to cloneNode
.
const clone = element.cloneNode(true)
After cloning, you need to place the clone
inside the DOM manually with append
or other methods.