Created
February 11, 2010 10:11
-
-
Save miya2000/301391 to your computer and use it in GitHub Desktop.
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 createDocumentFragment = (function() { | |
| if (document.createRange) { | |
| return function(contextElement, htmlStr) { | |
| var range = contextElement.ownerDocument.createRange(); | |
| range.selectNodeContents(contextElement); | |
| var df = range.createContextualFragment(htmlStr); | |
| range.detach(); | |
| return df; | |
| }; | |
| } | |
| else { | |
| return function(contextElement, htmlStr) { | |
| var dv = contextElement.ownerDocument.createElement(contextElement.nodeName); | |
| dv.innerHTML = htmlStr; | |
| var df = contextElement.ownerDocument.createDocumentFragment(); | |
| while(dv.firstChild) { | |
| df.appendChild(dv.firstChild); | |
| } | |
| return df; | |
| } | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment