Skip to content

Instantly share code, notes, and snippets.

@positlabs
Created December 16, 2021 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save positlabs/ffc2c046379d2cf326b4c0716488ec78 to your computer and use it in GitHub Desktop.
Save positlabs/ffc2c046379d2cf326b4c0716488ec78 to your computer and use it in GitHub Desktop.
Converts a string into an html element
/**
* @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