Skip to content

Instantly share code, notes, and snippets.

@odiak
Created April 5, 2011 02:25
Show Gist options
  • Save odiak/902916 to your computer and use it in GitHub Desktop.
Save odiak/902916 to your computer and use it in GitHub Desktop.
jQuery.create = function (tagName, innerText, attributes) {
var res;
if (typeof innerText === "undefined" || !innerText) {
innerText = "";
}
if (typeof attributes === "undefined" || !attributes) {
attributes = {};
}
if (tagName) {
var e = document.createElement(tagName);
if (innerText) {
e.innerHTML = innerText;
}
var attr;
for (attr in attributes) {
if (attributes.hasOwnProperty(attr)) {
e[attr] = attributes[attr];
}
}
res = $(e);
} else {
res = false;
}
return res;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment