Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created February 16, 2021 21:21
export function stringToHtml(html: string): ChildNode {
var template = document.createElement('template')
html = html.trim() // Never return a text node of whitespace as the result
template.innerHTML = html
return template.content.firstChild
}
// usage:
const div = stringToHtml('<div><span>nested</span> <span>stuff</span></div>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment