@mocanvas/editor · function

moveElementInto

declare function moveElementInto(parent: Element, element: Element): boolean

Move element to be the last child of parent, preserving its state.

The reason this is not parent.appendChild(element): removing and re-adding a node resets it. An <iframe> reloads, a <video> stops, a canvas loses its context, focus is lost. Node.moveBefore is the platform's answer and moves a node without disconnecting it; where it is unavailable this falls back to appendChild, which does reload — the same trade every browser without the new method forces.

Returns true when the move preserved state.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.