We can finally move elements in the browser with the moveBefore() API
Blog post from LogRocket
The moveBefore() API, recently introduced by Chrome, offers developers a streamlined method to reposition DOM elements without losing their state, which has been a limitation with traditional methods like appendChild() and insertBefore(). This API is particularly advantageous for web applications with complex animations or nuanced state management, as it enables an atomic move that preserves the internal state of elements, avoiding the state loss and performance issues associated with detaching and reattaching elements. The syntax of moveBefore() is similar to insertBefore(), making it familiar to developers, but it operates differently by maintaining the element's state during the move, thus simplifying code and enhancing performance, especially in large applications. While currently supported only in Chrome, other browsers like Safari and Firefox have shown interest, and developers are advised to implement fallback strategies for broader compatibility. The article highlights how moveBefore() can significantly improve user experiences in dynamic web applications, such as toggling layouts in a video lecture platform without interrupting the video playback.