Saturday, March 1, 2008

Setting css property in JavaScript calls

I wanted to dynamically set color for some of the options in a drop down list. I tried the following call:
document.getElementById("selectedKeys").options[i].style = 'color:red';

This did not work, at least in IE.

For this to work, i had to do something like this:
document.getElementById("selectedKeys").options[i].style.color = 'red';

No comments: