Created
December 16, 2021 20:52
-
-
Save positlabs/ffc2c046379d2cf326b4c0716488ec78 to your computer and use it in GitHub Desktop.
Converts a string into an html element
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
/** | |
* @param {String} HTML representing a single element | |
* @return {Element} | |
*/ | |
export function html2Element(html) { | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment