Skip to content

Instantly share code, notes, and snippets.

@Kreijstal
Created August 1, 2014 19:12
Show Gist options
  • Save Kreijstal/2c9e28e6610921137e64 to your computer and use it in GitHub Desktop.
Save Kreijstal/2c9e28e6610921137e64 to your computer and use it in GitHub Desktop.
Creates a new element.
function makeElem(elem, attributes, childnodes) {
var e = document.createElement(elem),l;
for (var a in attributes) {
if (a == "style") {
for (var d in attributes[a]) {
e.style[d] = attributes[a][d];
}
continue;
}
if (a == "__properties") {
for (d in attributes[a]) {
e[d] = attributes[a][d];
}
continue;
}
e.setAttribute(a, attributes[a])
}
if (childnodes && (l=childnodes.length)) {
for (var i = 0, c; i < l; i++) {
c = childnodes[i];
if (c.length && typeof c == "string") {
e.appendChild(document.createTextNode(c));
continue;
}
e.appendChild(c)
}
}
return e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment