Recursively finds a parent element with a specified attribute
Traverses up the DOM tree from the given element until it finds a parent with the specified attribute, or reaches the root.
The starting element
The parent element with the attribute, or the original element if not found
const button = document.querySelector('button');const dialog = findParent({ element: button, attr: 'role' });// Returns the closest ancestor with a 'role' attribute Copy
const button = document.querySelector('button');const dialog = findParent({ element: button, attr: 'role' });// Returns the closest ancestor with a 'role' attribute
Recursively finds a parent element with a specified attribute
Traverses up the DOM tree from the given element until it finds a parent with the specified attribute, or reaches the root.