Morphlex is a ~2KB (gzipped) DOM morphing library that transforms one DOM tree to match another while preserving element state and making minimal changes.
npm install morphlexOr use it directly from a CDN:
<script type="module">
  import { morph } from "https://www.unpkg.com/[email protected]/dist/morphlex.min.js"
</script>import { morph, morphInner } from "morphlex"
// Morph the entire element
morph(currentNode, referenceNode)
// Morph only the inner content
morphInner(currentNode, referenceNode)