Skip to content

Instantly share code, notes, and snippets.

@mmyoji
Last active September 1, 2021 09:41
Show Gist options
  • Save mmyoji/5cccefe384c4a98f75d631f70a778024 to your computer and use it in GitHub Desktop.
Save mmyoji/5cccefe384c4a98f75d631f70a778024 to your computer and use it in GitHub Desktop.
Parse HTML string to raw DOM
/**
* @example
* document.getElementById("messages").append(
* strToHTML('<div class="message">foo</div>')
* );
*/
function strToHtml(rawStr: string) {
var parser = new DOMParser();
var html = parser.parseFromString(rawStr, 'text/html');
return html.body.children[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment