create-node

2.0.3 • Public • Published

create-node

Converts an HTML string to a DOM node.

Build Status Coverage Status npm

Install

npm install --save create-node

or

jspm install create-node

Usage

Passing in markup with one top level element will return an HTMLElement (or something that inherits from it e.g HTMLDivElement)

import createNode from 'create-node';
 
const markup = `
<div>
  <span>hello</span>
  <span>world</span>
</div>`;
 
const node = createNode(markup);
// HTMLDivElement
 
node.querySelector('span:first-child').textContent;
// 'hello'
 
document.body.appendChild(node);

Passing in markup with multiple top level elements will return an HTMLCollection of HTMLElements.

import createNode from 'create-node';
 
const markup = `
<span>hello</span>
<span>world</span>`;
 
const collection = createNode(markup);
// HTMLCollection
 
collection[1].textContent;
// 'world'

License

MIT © Luke Childs

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.3
    24
    • latest

Version History

Package Sidebar

Install

npm i create-node

Weekly Downloads

25

Version

2.0.3

License

MIT

Last publish

Collaborators

  • lukechilds