Created
April 25, 2011 08:29
-
-
Save boopathi/940280 to your computer and use it in GitHub Desktop.
Set attributes to a DOM Element from a JSON object
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
/** | |
Usage: | |
var x = //Some DOM Element | |
var attr = { | |
style: "position: absolute; top: 0", | |
width: "500", | |
onmouseover: "this.style.background='#ddd'" | |
} | |
setAttributes(x,attr); | |
*/ | |
function setAttributes(obj,attr){ | |
for(i in attr) { | |
obj.setAttribute(i, attr[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment