Created
February 16, 2021 21:21
-
-
Save andreasvirkus/fbea20af025463ee1fd9d684ee5900ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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