Run results for: Swap element "in-place" with replaceWith() vs .outerHTML
Swap an DOM element with replaceWith() and compare with the .outerHTML method of replacing its content instead.
replaceWith()
- Pretty one-liner
- Breaks element attributes, inline style and scrollHeight/scrollWidth (fully re-render element)
.outerHTML
- Keeps attributes, inline style and scrollHeight/scrollWidth (partially re-render element)
- Breaks previous element references, "hacky" looking and sometimes perceptible (element may flash for a split second)