Skip to content

Instantly share code, notes, and snippets.

@alunny
Created August 13, 2010 18:50
Show Gist options
  • Save alunny/523349 to your computer and use it in GitHub Desktop.
Save alunny/523349 to your computer and use it in GitHub Desktop.
a stab at a new wrap function for xui
// private method
// Wraps the HTML in a TAG, Tag is optional
// If the html starts with a Tag, it will wrap the context in that tag.
// doesn't ACTUALLY work
function wrap(xhtml, tag) {
// new approach
// createDocumentFragment
var docFrag = document.createDocumentFragment(),
dummy,
wrapTag;
if (tag) {
wrapTag = document.createElement(tag);
wrapTag.innerHTML = xhtml;
docFrag.appendChild(wrapTag);
} else {
dummy = document.createElement('div'),
dummy.innerHTML = xhtml;
while (dummy.children.length)
docFrag.appendChild(dummy.children[0]);
}
return docFrag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment