Created
January 26, 2024 02:09
-
-
Save natescode/f7aed217e24d4ba6c034a7c7f57b08a2 to your computer and use it in GitHub Desktop.
Parse Template String as 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
String.prototype.toHtml = function () { | |
let element = new DOMParser().parseFromString(this, 'text/html').body.firstChild; | |
return element; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment