Gets the closest ancestor that matches a selector string starting from the passed HTMLElement.
Parameters:
Name | Type | Description |
---|---|---|
el | HTMLElement | The element to search upwards from. |
selector | string | The selector string to search for. |
- Since
- 1.0.0
- Source
Returns:
An HTMLElement of null if not matching parent found.
- Type:
- HTMLElement |
null
Example
import { getClosest } from "@gravityforms/utils";
function Example() {
const node = document.getElementById( 'example' );
const ancestor = getClosest( node, '.some-example-ancestor' );
}