@xyo-network/react-shared
Version:
Common React library for all XYO projects that use React
11 lines (10 loc) • 322 B
text/typescript
export const findParent = (tagName: string, element: HTMLElement | null = null) => {
let currentElement = element
while (currentElement) {
if (currentElement.tagName.toLowerCase() === tagName.toLowerCase()) {
return currentElement
} else {
currentElement = currentElement.parentElement
}
}
}