dom-serialization
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

DOM Serialization

Serialize the DOM

Q. Why don't you use innerHTML?

: when you use innerHTML you lose tree structure if there are adjacent text nodes.

            span
          /       \
  text node       text node

dom-serialization serialize the DOM with keeping tree structure. So you can keep tree structure when you deserialize from serialized string.

Getting started

npm install dom-serialization
import { serialize, deserialize } from 'dom-serialization';

const dom = document.createElement('div');
dom.appendChild(document.createTextNode('hello'));
dom.appendChild(document.createTextNode('world'));

const code = serialize(dom);
console.log(deserialize(code));

Readme

Keywords

Package Sidebar

Install

npm i dom-serialization

Weekly Downloads

0

Version

1.2.0

License

MIT

Unpacked Size

12.8 kB

Total Files

6

Last publish

Collaborators

  • swimyoung