Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukechilds/create-node
Converts an HTML string to a dom node
https://github.com/lukechilds/create-node
dom dom-manipulation dom-node templating
Last synced: 3 months ago
JSON representation
Converts an HTML string to a dom node
- Host: GitHub
- URL: https://github.com/lukechilds/create-node
- Owner: lukechilds
- License: mit
- Created: 2016-05-22T16:08:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-10T23:35:25.000Z (over 5 years ago)
- Last Synced: 2024-11-01T23:50:23.879Z (3 months ago)
- Topics: dom, dom-manipulation, dom-node, templating
- Language: JavaScript
- Size: 37.1 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# create-node
Converts an HTML string to a DOM node.
[![Build Status](https://travis-ci.org/lukechilds/create-node.svg?branch=master)](https://travis-ci.org/lukechilds/create-node)
[![Coverage Status](https://coveralls.io/repos/github/lukechilds/create-node/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/create-node?branch=master)
[![npm](https://img.shields.io/npm/v/create-node.svg)](https://www.npmjs.com/package/create-node)## Install
```shell
npm install --save create-node
```or
```shell
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`)
```js
import createNode from 'create-node';const markup = `
`;
hello
worldconst node = createNode(markup);
// HTMLDivElementnode.querySelector('span:first-child').textContent;
// 'hello'document.body.appendChild(node);
```Passing in markup with multiple top level elements will return an `HTMLCollection` of `HTMLElement`s.
```js
import createNode from 'create-node';const markup = `
hello
world`;const collection = createNode(markup);
// HTMLCollectioncollection[1].textContent;
// 'world'
```## License
MIT © Luke Childs