Skip to content

Instantly share code, notes, and snippets.

@bloodyowl
Created October 22, 2012 10:30
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 bloodyowl/3930814 to your computer and use it in GitHub Desktop.
Save bloodyowl/3930814 to your computer and use it in GitHub Desktop.
String to Element
String.prototype.toElement = function() {
var childNodes, fragment, i, item, sandbox, _i, _len;
sandbox = document.createElement("div");
fragment = document.createDocumentFragment();
sandbox.innerHTML = this;
childNodes = $A(sandbox.childNodes);
for (i = _i = 0, _len = childNodes.length; _i < _len; i = ++_i) {
item = childNodes[i];
fragment.appendChild(item);
}
return fragment;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment