Skip to content

Commit

Permalink
convert util DOMUtils to TS (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
spasovski authored May 10, 2021
1 parent 4ceabe6 commit ec3570b
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
* @returns DOM element matching the given class or null if not found
*/

export function getClosestByClassName(element, className) {
export function getClosestByClassName(
element: Element | null,
className: string
): Element | null {
if (!element) {
return null;
}
if (element.classList && element.classList.contains(className)) {
return element;
}
return getClosestByClassName(element.parentNode, className);
return element.closest(`.${className}`);
}

export default { getClosestByClassName };

0 comments on commit ec3570b

Please sign in to comment.