Gets the closest ancestor that matches a selector string starting from the passed HTMLElement.

Parameters:
NameTypeDescription
elHTMLElement

The element to search upwards from.

selectorstring

The selector string to search for.

Since
  • 1.0.0
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' );
}