js-draw
Version:
Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript.
12 lines (11 loc) • 371 B
JavaScript
/** Returns the first ancestor of the given node (or the node itself) that is an HTMLElement */
const firstElementAncestorOfNode = (node) => {
if (node instanceof HTMLElement) {
return node;
}
else if (node?.parentNode) {
return firstElementAncestorOfNode(node.parentNode);
}
return null;
};
export default firstElementAncestorOfNode;