Skip to content

Instantly share code, notes, and snippets.

@o-t-w
Created April 21, 2025 17:42
Show Gist options
  • Save o-t-w/aefa44fd1f5c05f74e811c487a3d9ddc to your computer and use it in GitHub Desktop.
Save o-t-w/aefa44fd1f5c05f74e811c487a3d9ddc to your computer and use it in GitHub Desktop.
function createNode(html) {
const nodeList = Document.parseHTMLUnsafe(html).body.childNodes;
const fragment = new DocumentFragment();
Array.from(nodeList).forEach(node => {
fragment.appendChild(node);
});
return fragment;
}
document.body.append(createNode('<h2>hello</h2><p>world</p>'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment