Inserts an HTMLElement before another one that is passed in.

Parameters:
NameTypeDescription
elementHTMLElement | NodeList

The element to insert.

targetHTMLElement | NodeList

The target to insert the element before.

Since
  • 1.0.0
Returns:
Type: 
void
Example
import { insertBefore, getNodes } from "@gravityforms/utils";

function Example() {
  const target = getNodes( '.some-custom-selector', false, document.body, true )[ 0 ];
  const div = document.createElement( 'div' );
  insertBefore( div, target );
}