You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Luke Childs bd0f285221
chore(package): update xo to version 0.20.1 (#13)
7 years ago
src Allow document instance to be passed in 8 years ago
test Replace browser-env with window 8 years ago
.gitignore add .nyc_output to .gitignore 9 years ago
.npmignore Add .npmignore to fix npm issue 9 years ago
.travis.yml Don't send email on success 8 years ago
LICENSE Add LICENSE file 8 years ago
README.md Remove Greenkeeper badge 7 years ago
package.json chore(package): update xo to version 0.20.1 (#13) 7 years ago

README.md

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