dom_get-node.js

import getNodes from './get-nodes';

/**
 * @module getNode
 * @description 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.
 *
 * @since 1.3.2
 *
 * @param {string}      selector The selector string to search for. If 'custom' arg is false (default)
 *                               then we search for [data-js="selector"].
 * @param {HTMLElement} parent   Parent node to search from. Defaults to document.
 * @param {boolean}     custom   Is this a custom selector where we don't want to use the
 *                               data-js attribute? Defaults to false.
 * @requiresgetNodes
 *
 * @example
 * import { getNode } from "@gravityforms/utils";
 *
 * function Example() {
 *   const element = getNode( 'my-data-js-selector' );
 * }
 *
 * @return {HTMLElement|null} Returns the element from the DOM, or null if element was not found.
 */
export default function( selector = '', parent = document, custom = false ) {
	const nodes = getNodes( selector, false, parent, custom );
	return nodes.length > 0 ? nodes[ 0 ] : null;
}