Serializes any DOM node into a String
outerHTML, but it works with:
- DOM elements
- Text nodes
- Comment nodes
- NodeLists / Arrays
For custom serialization logic, a "serialize" event is dispatched on
Node which event listeners can override the default behavior on by
event.detail.serialize property to a String or other Node.
The "serialize" event bubbles, so it could be a good idea to utilize
event delegation on a known root node that will be serialized.
event.serializeTarget property to check which
currently being serialized.
$ npm install dom-serialize
var serialize = ;var node;// works with Text nodesnode = document;console;// works with DOM elementsnode = document;node;nodefirstChild;console;// custom "serialize" eventnodefirstChild;console;// you can also just pass a function in for a one-time serializerconsole;
foo & <bar> <body><strong>hello</strong></body> <body>pwn</body> <body>…</body>