When I set the background colour of an element using
tdRef.style.bac kgroundColor and then read it back, Firefox always
gives rgb(r, g, b) regardless of whether I've used rgb(...) or #rrggbb
to set it.
If I use tdRef.bgColor to set/read the value, I always get #rrggbb
regardless of whether I've used rgb(...) or #rrggbb.
IE, on the other hand, when using style.backgroun dColor reports back in
whatever format was used (either rgb(...) or #rrggbb), but, like
Firefox, always gives #rrggbb for the bgColor method.
My question is which method is most consistent across various browsers?
I want to use style.backgroun dColor (since some browsers don't support
bgColor, I guess it's a legacy from the ver 4 browser days). If I
decide to use rgb(...), is it consistently supported by other browsers
or do some report in #rrggbb regardless?
A bit of play code follows...
Cheers, Rob.
<script type="text/javascript">
function setColor(x) {
x.style.backgro undColor='#0033 66';
//x.style.backgro undColor='rgb(0 , 51, 102)';
alert(x.style.b ackgroundColor) ;
}
function setColor2(x) {
x.bgColor='rgb( 0, 51, 102)';
alert(x.bgColor );
}
</script>
<table border="1"><tr>
<td width="20px" height="20px"
onclick="setCol or(this);"></td>
</tr><tr>
<td width="20px" height="20px"
onclick="setCol or2(this);"></td>
</tr></table>
Comment