JavaScript: change CSS
This is a simple script that will change the CSS of any object.
You send the function the ID, the CSS attribute you want to change, and the value..
I actually struggled a bit with this as using dot syntax for the CSS attribute would not work. I had to use brackets.
<div id=”myDiv” onclick=”CSS_change(‘myDiv’,'color’,'#ff0000′)”>Change Color</div>
function CSS_change(ID, CSSATTRIB, VALUE)
{
var obj_style = document.getElementById(ID).style;
obj_style[CSSATTRIB] = VALUE;
}
Categories: JavaScript