Skip to content

closestPierce

type: function
since: v2.6.0

The closestPierce function is a utility function that extends the capabilities of the native Element.closest method by traversing shadow DOM boundaries. This means that it can be used to find the closest element matching a given selector, even if that element is contained within a shadow DOM.

Usage

import { closestPierce } from '@mustib/utils/browser';
closestPierce('light dom selector', elementOrShadowDomElement)

Definition

function closestPierce(
selector: string,
startEl: HTMLElement | null
): HTMLElement | null { }

Parameters

  1. selector
    type selector = string;
    • The CSS selector to search for.
  2. startEl
    type startEl = HTMLElement | null;
    • The element from which to start searching.

Returns

type T = HTMLElement | null;