Skip to content

Instantly share code, notes, and snippets.

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 christophemarois/136d9a7825d2694df17f to your computer and use it in GitHub Desktop.
Save christophemarois/136d9a7825d2694df17f to your computer and use it in GitHub Desktop.
/*
* Generate document fragment from HTML string
* @param { HTML string } str
*
* Example:
* -> document.createDocumentFragmentFromString('<b>sup</b>&nbsp;');
* <- #document-fragment
*/
document.createDocumentFragmentFromString = function (str) {
var container = document.createElement('div')
, fragment = document.createDocumentFragment();
container.innerHTML = str;
var i; while ( i = container.firstChild ) fragment.appendChild(i);
return fragment;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment