Skip to content

Instantly share code, notes, and snippets.

@natescode
Created January 26, 2024 02:09
Show Gist options
  • Save natescode/f7aed217e24d4ba6c034a7c7f57b08a2 to your computer and use it in GitHub Desktop.
Save natescode/f7aed217e24d4ba6c034a7c7f57b08a2 to your computer and use it in GitHub Desktop.
Parse Template String as HTML element
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