{"id":8131,"date":"2025-12-31T18:03:28","date_gmt":"2025-12-31T23:03:28","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=8131"},"modified":"2025-12-31T18:03:30","modified_gmt":"2025-12-31T23:03:30","slug":"preserve-state-while-moving-elements-in-the-dom","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/preserve-state-while-moving-elements-in-the-dom\/","title":{"rendered":"Preserve State While Moving Elements in the DOM"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.bram.us\/2025\/01\/16\/move-elements-around-the-dom-while-preserving-their-state-with-movebefore\/\">Bramus wrote this almost a year ago<\/a>, but I&#8217;d still call it a relatively new feature of JavaScript and one <em>very<\/em> worth knowing about.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>With\u00a0<code>Node.prototype.moveBefore<\/code>\u00a0you can move elements around a DOM tree, without resetting the element&#8217;s state.<\/p>\n<\/blockquote>\n\n\n\n<p>You don&#8217;t need it to maintain event listeners, but, as Bramus notes, it&#8217;ll keep an iframe loaded, animations running, dialogs open, etc. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bramus wrote this almost a year ago, but I&#8217;d still call it a relatively new feature of JavaScript and one very worth knowing about. With\u00a0Node.prototype.moveBefore\u00a0you can move elements around a DOM tree, without resetting the element&#8217;s state. You don&#8217;t need it to maintain event listeners, but, as Bramus notes, it&#8217;ll keep an iframe loaded, animations [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8133,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[3,431],"class_list":["post-8131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-javascript","tag-movebefore"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2025\/12\/pexels-photo-7203813.jpeg?fit=1880%2C1253&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/8131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=8131"}],"version-history":[{"count":1,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/8131\/revisions"}],"predecessor-version":[{"id":8134,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/8131\/revisions\/8134"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/8133"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=8131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=8131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=8131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}