Add closestParent

This commit is contained in:
Leonabcd123 2025-12-21 16:11:00 +02:00
parent 03eef0485e
commit a9e5980fea
2 changed files with 8 additions and 6 deletions

View file

@ -1092,7 +1092,7 @@ qs(".pageAccount")?.onChild(
async (event) => {
const target = new ElementWithUtils(event.childTarget as HTMLElement);
const resultId: string = target
.closest("tr")
.closestParent("tr")
?.getAttribute("data-id") as string;
if (target.hasClass("loading")) return;
if (target.hasClass("disabled")) return;

View file

@ -553,12 +553,14 @@ export class ElementWithUtils<T extends HTMLElement = HTMLElement> {
}
/**
* Get the first element matching a selector, starting from this.native and going
up through its parents
* Get the first parent that matches a selector
*/
closest(selector: string): ElementWithUtils | null {
const el = this.native.closest(selector) as HTMLElement;
return el !== null ? new ElementWithUtils(el) : null;
closestParent(selector: string): ElementWithUtils | null {
const closestParent = this.native.parentElement?.closest(
selector,
) as HTMLElement;
return closestParent !== null ? new ElementWithUtils(closestParent) : null;
}
/**