A utility to get nodes and return an array/nodelist of them. Abstracts the need to pass [data-js="some-string"]
as simply some-string
. Will also convert the nodelist to an array if that arg is true, and has a parent to search from. A custom selector string can be used if the 4th argument is true.
Parameters:
Name | Type | Description |
---|---|---|
selector | string | The selector string to search for. If arg 4 is false (default) then we search for [data-js="selector"]. |
convert | boolean | Convert the NodeList to an array? Then we can Array.forEach directly. Uses convertElements from above. |
node | HTMLElement | | Parent node to search from. Defaults to document. |
custom | boolean | Is this a custom selector where we don't want to use the data-js attribute? |
- Since
- 1.0.0
- Source
Returns:
Returns either a NodeList or an Array of HTMLElements.
- Type:
- NodeList |
Array
Example
import { getNodes } from "@gravityforms/utils";
function Example() {
const nodes = getNodes( '.some-custom-selector', true, document.body, true );
return nodes;
}