Skip to content

Instantly share code, notes, and snippets.

@lazysand
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazysand/21a69f59dbe038c5b78c to your computer and use it in GitHub Desktop.
Save lazysand/21a69f59dbe038c5b78c to your computer and use it in GitHub Desktop.
String.prototype.toDOM
//http://stackoverflow.com/a/16349647/2039143
String.prototype.toDOM=function(){
var d=document
,i
,a=d.createElement("div")
,b=d.createDocumentFragment();
a.innerHTML=this;
while(i=a.firstChild)b.appendChild(i);
return b;
};
var foo="<img src='//placekitten.com/100/100'>foo<i>bar</i>".toDOM();
document.body.appendChild(foo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment