dom_insert-after.js

/**
 * @module insertAfter
 * @description Inserts an HTMLElement after 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 after.
 *
 * @return {void}
 *
 * @example
 * import { insertAfter, getNodes } from "@gravityforms/utils";
 *
 * function Example() {
 *   const target = getNodes( '.some-custom-selector', false, document.body, true )[ 0 ];
 *   const div = document.createElement( 'div' );
 *   insertAfter( div, target );
 * }
 *
 */
export default function insertAfter( element, target ) {
	target.parentNode.insertBefore(
		element,
		target.nextElementSibling
	);
}