Skip to content

Instantly share code, notes, and snippets.

@boopathi
Created April 25, 2011 08:29
Show Gist options
  • Save boopathi/940280 to your computer and use it in GitHub Desktop.
Save boopathi/940280 to your computer and use it in GitHub Desktop.
Set attributes to a DOM Element from a JSON object
/**
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