1. domify
Turn a HTML string into DOM elements, cross-platform
domify
Package: domify
Created by: sindresorhus
Last modified: Fri, 17 Nov 2023 20:46:10 GMT
Version: 2.0.0
License: MIT
Downloads: 544,132
Repository: https://github.com/sindresorhus/domify

Install

npm install domify
yarn add domify

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().

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code