Created
July 22, 2014 15:48
-
-
Save christophemarois/136d9a7825d2694df17f to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* Generate document fragment from HTML string | |
* @param { HTML string } str | |
* | |
* Example: | |
* -> document.createDocumentFragmentFromString('<b>sup</b> '); | |
* <- #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