Created
May 10, 2014 10:18
-
-
Save ChaseWest/1027e5ef3166f7d5126f to your computer and use it in GitHub Desktop.
Parse HTML string without DOMParser API
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 frag = document.createDocumentFragment(), | |
el = document.createElement( "div" ); | |
el.setAttribute("id", "wrapper"); | |
el.innerHTML = HTML; | |
frag.appendChild(el); | |
return frag.querySelector("div#wrapper").children[0]; | |
} | |
console.log(parseHTML(HTML)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment