dom_insert-before.js

/**
 * @module insertBefore
 * @description Inserts an HTMLElement before another one that is passed in.
 *
 * @since 1.0.0
 *
 * @param {HTMLElement|NodeList} element The element to insert.
 * @param {HTMLElement|NodeList} target  The target to insert the element before.
 *
 * @return {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 );
 * }
 *
 */
export default function insertBefore( element, target ) {
	target.parentNode.insertBefore( element, target );
}