Created
October 28, 2013 18:01
-
-
Save apla/7201557 to your computer and use it in GitHub Desktop.
make element js function
This file contains hidden or 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 MakeEl (name, attributes) { | |
var el = document.createElement (name); | |
if (typeof attributes == 'object') { | |
for (var i in attributes) { | |
el.setAttribute (i, attributes[i]); | |
if (i.toLowerCase() == 'class') { | |
el.className = attributes[i]; // for IE compatibility | |
} else if (i.toLowerCase() == 'style') { | |
el.style.cssText = attributes[i]; // for IE compatibility | |
} | |
} | |
} | |
for (var i = 2; i<arguments.length; i++) { | |
var val = arguments[i]; | |
if (typeof val == 'string') | |
val = document.createTextNode( val ); | |
if (el && el.appendChild) | |
el.appendChild (val); | |
} | |
return el; | |
} |
Author
apla
commented
Oct 28, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment