scramjet/src/html/cloner.ts
2024-07-12 02:28:17 -04:00

25 lines
No EOL
587 B
TypeScript

export default class Clone {
el: HTMLElement;
copy: HTMLElement
constructor(element: HTMLElement) {
this.el = element;
this.copy = document.createElement(element.tagName);
for (const attr of element.getAttributeNames()) {
this.copy.setAttribute(attr, element.getAttribute(attr));
}
if (element.innerHTML) {
this.copy.innerHTML = element.innerHTML;
}
}
insertCopy() {
this.el.insertAdjacentElement("afterend", this.copy);
}
removeElement() {
this.el.remove();
}
}