string-to-dom

string-to-dom JS library on GitHub string-to-dom JS library on npm Download string-to-dom JS library

Add a string of HTML to the DOM and return the new element.

Version 0.1.5 License MIT Vulnerabilities 0
string-to-dom has no homepage
string-to-dom JS library on GitHub
string-to-dom JS library on npm
Download string-to-dom JS library
Keywords
domstringhtmltestutilutilityliblibrary

string-to-dom

Travis CI build status Dependency Status View on npm View on npm

Add a string of HTML to the DOM and return the new HTML element.

Uses insertAdjacentHTML to add a given string to the DOM in an efficient manner and return the newly created HTML element.

Useful in test suites for setting up HTML to assert against.

Install

npm install --save string-to-dom

Usage

var stringToDom = require('string-to-dom');

// Add the <p> tag to the page (right after the <body> tag).
// `message` is the newly created HTML element.
var message = stringToDom('<p>Hello, World!</p>');

// Optionally add to a particular node on the page:
var target = document.getElementById('my-form')
var button = stringToDom('<button class="btn">Click me!</button>', target)

API

See the API docs for full documentation.

License

MIT © Dana Woodman