JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2940078
  • Score
    100M100P100Q197988F
  • License MIT

Serializes any DOM node into a String

Package Exports

  • dom-serialize

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dom-serialize) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dom-serialize

Serializes any DOM node into a String

Sauce Test Status

Build Status

Works with Text nodes, DOM elements, etc.

Dispatches a custom "serialize" event on every Node which event listeners can override the default behavior on by setting the event.detail.serialize property to a String or other Node.

Installation

$ npm install dom-serialize

Example

var serialize = require('dom-serialize');
var node;

// works with Text nodes
node= document.createTextNode('foo & <bar>');
console.log(serialize(node));

// works with DOM elements
node = document.createElement('body');
node.appendChild(document.createElement('strong'));
node.firstChild.appendChild(document.createTextNode('hello'));
console.log(serialize(node));

// custom "serialize" event
node.firstChild.addEventListener('serialize', function (event) {
  event.detail.serialize = 'pwn';
}, false);
console.log(serialize(node));
&#60;foo&#62; &#38; &#60;bar&#62;
<body><strong>hello</strong></body>
<body>pwn</body>