Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

domify

sindresorhus558.7kMIT2.0.0TypeScript support: included

Turn a HTML string into DOM elements, cross-platform

dom, html, client, browser, component, element, elements, string, document

readme

domify

Turn a HTML string into DOM elements, cross-platform

Usage

Works out of the box in the browser:

import domify from 'domify';

document.addEventListener('DOMContentLoaded', () => {
    const element = domify('<p>Hello <em>there</em></p>');
    document.body.appendChild(element);
});

You can also run it in Node.js and other non-browser environments by passing a custom implementation of document:

import {JSDOM} from 'jsdom';

const jsdom = new JSDOM();

domify('<p>Hello <em>there</em></p>', jsdom.window.document);

Note: For browser-only use, prefer DOMParser.parseFromString().