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.
Welcome! Unfortunately, you donβt have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson