@@ -826,6 +826,61 @@ public void insertAdjacentHTML(final String position, final String text) {
826826 parseHtmlSnippet (proxyDomNode , text );
827827 }
828828
829+ /**
830+ * Moves a given Node inside the invoking node as a direct child, before a given reference node.
831+ *
832+ * @param context the JavaScript context
833+ * @param scope the scope
834+ * @param thisObj the scriptable
835+ * @param args the arguments passed into the method
836+ * @param function the function
837+ */
838+ @ JsxFunction ({CHROME , EDGE , FF })
839+ public static void moveBefore (final Context context , final Scriptable scope ,
840+ final Scriptable thisObj , final Object [] args , final Function function ) {
841+ ((HTMLElement ) thisObj ).moveBeforeImpl (args );
842+ }
843+
844+ /**
845+ * Add a DOM node as a child to this node before the referenced node.
846+ * If the referenced node is null, append to the end.
847+ * @param args the arguments
848+ * @throws DOMException in case of problems
849+ */
850+ protected void moveBeforeImpl (final Object [] args ) throws org .w3c .dom .DOMException {
851+ if (args .length < 2 ) {
852+ throw JavaScriptEngine .typeError (
853+ "Failed to execute 'moveBefore' on 'Element': 2 arguments required, but only 0 present." );
854+ }
855+
856+ final Object movedNodeObject = args [0 ];
857+ if (!(movedNodeObject instanceof Node )) {
858+ throw JavaScriptEngine .typeError (
859+ "Failed to execute 'moveBefore' on 'Element': parameter 1 is not of type 'Node'." );
860+ }
861+ final Object referenceNodeObject = args [1 ];
862+ if (referenceNodeObject != null && !(referenceNodeObject instanceof Node )) {
863+ throw JavaScriptEngine .typeError (
864+ "Failed to execute 'moveBefore' on 'Element': parameter 2 is not of type 'Node'." );
865+ }
866+
867+ try {
868+ if (referenceNodeObject == null ) {
869+ getDomNodeOrDie ().moveBefore (((Node ) movedNodeObject ).getDomNodeOrDie (), null );
870+ return ;
871+ }
872+
873+ getDomNodeOrDie ().moveBefore (
874+ ((Node ) movedNodeObject ).getDomNodeOrDie (), ((Node ) referenceNodeObject ).getDomNodeOrDie ());
875+ }
876+ catch (final org .w3c .dom .DOMException e ) {
877+ throw JavaScriptEngine .asJavaScriptException (
878+ getWindow (),
879+ "Failed to execute 'moveChild' on '" + this + ": " + e .getMessage (),
880+ e .code );
881+ }
882+ }
883+
829884 /**
830885 * Parses the specified HTML source code, appending the resulting content at the specified target location.
831886 * @param target the node indicating the position at which the parsed content should be placed
@@ -1687,6 +1742,7 @@ public boolean toggleAttribute(final String name, final Object force) {
16871742 /**
16881743 * Inserts a set of Node objects or string objects after the last child of the Element.
16891744 * String objects are inserted as equivalent Text nodes.
1745+ *
16901746 * @param context the context
16911747 * @param scope the scope
16921748 * @param thisObj this object
@@ -1706,6 +1762,7 @@ public static void append(final Context context, final Scriptable scope,
17061762 /**
17071763 * Inserts a set of Node objects or string objects before the first child of the Element.
17081764 * String objects are inserted as equivalent Text nodes.
1765+ *
17091766 * @param context the context
17101767 * @param scope the scope
17111768 * @param thisObj this object
@@ -1725,6 +1782,7 @@ public static void prepend(final Context context, final Scriptable scope,
17251782 /**
17261783 * Replaces the existing children of a Node with a specified new set of children.
17271784 * These can be string or Node objects.
1785+ *
17281786 * @param context the context
17291787 * @param scope the scope
17301788 * @param thisObj this object
0 commit comments