Skip to content

Commit

Permalink
HTMLElement: Implement more useful getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Maluscat committed Sep 28, 2024
1 parent a3e41a9 commit 0959b6b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,27 @@ export default class HTMLElement extends Node {
}
}

/** Get all childNodes of type {@link HTMLElement}. */
public get children(): HTMLElement[] {
const children = [];
for (const childNode of this.childNodes) {
if (childNode instanceof HTMLElement) {
children.push(childNode);
}
}
return children;
}

public get firstElementChild(): HTMLElement | undefined {
return this.children[0];
}
public get lastElementChild(): HTMLElement | undefined {
return this.children[this.children.length - 1];
}
public get childElementCount(): number {
return this.children.length;
}

public get classNames() {
return this.classList.toString();
}
Expand Down

0 comments on commit 0959b6b

Please sign in to comment.