The Element.moveBefore() method moves a node so it becomes a direct child of this element, placed before a reference node (MDN). Unlike insertBefore(), it does not remove-and-reinsert — so focus, animations, and similar state can survive.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call el.moveBefore. Start with this line.
JavaScript
parent.moveBefore(movedNode, referenceNode)
Call
What it does
parent.moveBefore(movedNode, referenceNode)
Primary signature.
el.moveBefore(...)
Call with the arguments your case needs.
Built into the browser. Call moveBefore(...) on an Element — no import required.
Library declarations
JavaScript
parent.moveBefore(movedNode, referenceNode)
Parameters
Parameter
Description
Parent element
Required. New home for movedNode
movedNode
Required. Element or CharacterData to move
referenceNode
Required. Insert before this child, or end if null
Return Value
Return Value
Description
*
undefined
JavaScript Examples
Example 1 — Toggle Position (MDN)
Move a box before section 2, then back before section 1.
Feature-detect with typeof parent.moveBefore === "function".
Prefer moveBefore so state can be preserved.
Fall back to insertBefore on Limited / missing engines.
Report which path ran so you can verify in DevTools.
Compatibility
Browser Support
Element.moveBefore() is Limited availability on MDN (not Baseline). Support includes recent Chromium and Firefox; Safari currently lacks support. See the MDN moveBefore() reference.
✓ Limited availability
Element.moveBefore()
State-preserving DOM move. Feature-detect and fall back to insertBefore().
LimitedNot Baseline
Google Chrome133+
Yes
Microsoft Edge133+
Yes
Mozilla Firefox140+
Yes
Opera118+
Yes
Apple SafariNot supported
No
Internet ExplorerNot supported
No
moveBefore()Partial
Bottom line: Prefer moveBefore when available for focus/animation-safe reorders. Always keep an insertBefore fallback.
Frequently Asked Questions
MDN: it moves a given Node inside the invoking element as a direct child, before a reference node. Unlike insertBefore(), it does not remove and reinsert the node, so element state is preserved.
MDN marks Element.moveBefore() as Limited availability (not Baseline). It is not Deprecated or Non-standard, but support is incomplete — feature-detect before production use.
Nothing useful — the return value is undefined (MDN).
If referenceNode is null, movedNode is inserted at the end of the invoking element’s child nodes (MDN).
insertBefore() removes and reinserts the node, which can reset focus, animations, and popover state. moveBefore() moves the node while preserving that state (MDN).
HierarchyRequestError for invalid moves (wrong document, connected/disconnected mismatch, ancestor moves, non-Element/CharacterData). NotFoundError if referenceNode is not a child of the parent. TypeError if the second argument is missing.