Last active
September 1, 2021 09:41
-
-
Save mmyoji/5cccefe384c4a98f75d631f70a778024 to your computer and use it in GitHub Desktop.
Parse HTML string to raw DOM
This file contains 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
/** | |
* @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