Created
May 10, 2014 09:48
-
-
Save ChaseWest/861993bdb45573daa669 to your computer and use it in GitHub Desktop.
Parse HTML string to document object and insert into DOM
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
var HTML = "<div></span>Test</span></div>"; | |
var body = document.querySelector("body"); | |
function parseHTML(htmlString){ | |
var parser = new DOMParser(); | |
var fragment = document.createDocumentFragment(); | |
fragment.appendChild(parser.parseFromString(htmlString, "text/html").querySelector("body")); | |
body.appendChild(fragment); | |
} | |
parseHTML(HTML); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment