Created
August 1, 2014 19:12
-
-
Save Kreijstal/2c9e28e6610921137e64 to your computer and use it in GitHub Desktop.
Creates a new element.
This file contains 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
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