Skip to content

Commit

Permalink
Allow append to receive multiple elements and implement prepend a…
Browse files Browse the repository at this point in the history
…s well

This might come in handy.
  • Loading branch information
TomasHubelbauer committed Oct 13, 2024
1 parent ec3e311 commit d43c587
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,22 @@ class Element implements Node {
// Note that this information is not exposed in the `Element` web interface
isVoid: boolean;

append(element: Element) {
this.children.push(element);
element.parentNode = this;
element.parentElement = this;
element.ownerDocument = this.ownerDocument;
prepend(...elements: Element[]) {
this.children.unshift(...elements);
for (const element of elements) {
element.parentNode = this;
element.parentElement = this;
element.ownerDocument = this.ownerDocument;
}
}

append(...elements: Element[]) {
this.children.push(...elements);
for (const element of elements) {
element.parentNode = this;
element.parentElement = this;
element.ownerDocument = this.ownerDocument;
}
}

get outerHTML() {
Expand Down

0 comments on commit d43c587

Please sign in to comment.