Skip to content

Instantly share code, notes, and snippets.

@Legends
Created December 20, 2019 16:32
Show Gist options
  • Select an option

  • Save Legends/91e880f13e3a13225c96ee24a620f7f4 to your computer and use it in GitHub Desktop.

Select an option

Save Legends/91e880f13e3a13225c96ee24a620f7f4 to your computer and use it in GitHub Desktop.
var doc = document, win = window;
var frag;
function parseHTML(str) {
if (!frag) {
frag = doc.implementation.createHTMLDocument(null);
var base = frag.createElement("base");
base.href = doc.location.href;
frag.head.appendChild(base);
}
frag.body.innerHTML = str;
return frag.body.childNodes;
}
// usage:
parseHTML("<p class='wixen'><span>hallo</span></p>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment