Skip to content

Commit ab974ee

Browse files
committed
♻️ refactor findParent to use HTMLElement.closest
1 parent c4727b2 commit ab974ee

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

src/mnml.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,7 @@ export const mnml = (() => {
8080
};
8181

8282
const findParent = (elem: HTMLElement, selector: string): HTMLElement | null => {
83-
let parent = elem.parentElement;
84-
if (!parent || !parent.matches) {
85-
return null;
86-
}
87-
while (!parent.matches(selector)) {
88-
parent = parent.parentElement;
89-
if (!parent || !parent.matches) {
90-
parent = null;
91-
break;
92-
}
93-
}
94-
return parent;
83+
return elem.closest(selector) || null;
9584
};
9685

9786
const findParents = (elem: HTMLElement, selector: string): HTMLElement[] => {

0 commit comments

Comments
 (0)