Gets a specific element from the DOM. If multiple elements match the selector, the first one is returned. This method, or getNodes should be used at all times for getting nodes throughout our codebase. Please use the data-js attribute whenever possible.

Parameters:
NameTypeDescription
selectorstring

The selector string to search for. If 'custom' arg is false (default) then we search for [data-js="selector"].

parentHTMLElement

Parent node to search from. Defaults to document.

customboolean

Is this a custom selector where we don't want to use the data-js attribute? Defaults to false.

Since
  • 1.3.2
Returns:

Returns the element from the DOM, or null if element was not found.

Type: 
HTMLElement | null
Example
import { getNode } from "@gravityforms/utils";

function Example() {
  const element = getNode( 'my-data-js-selector' );
}