R
RobG
When I set the background colour of an element using
tdRef.style.backgroundColor 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.backgroundColor 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.backgroundColor (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.backgroundColor='#003366';
//x.style.backgroundColor='rgb(0, 51, 102)';
alert(x.style.backgroundColor);
}
function setColor2(x) {
x.bgColor='rgb(0, 51, 102)';
alert(x.bgColor);
}
</script>
<table border="1"><tr>
<td width="20px" height="20px"
onclick="setColor(this);"></td>
</tr><tr>
<td width="20px" height="20px"
onclick="setColor2(this);"></td>
</tr></table>
tdRef.style.backgroundColor 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.backgroundColor 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.backgroundColor (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.backgroundColor='#003366';
//x.style.backgroundColor='rgb(0, 51, 102)';
alert(x.style.backgroundColor);
}
function setColor2(x) {
x.bgColor='rgb(0, 51, 102)';
alert(x.bgColor);
}
</script>
<table border="1"><tr>
<td width="20px" height="20px"
onclick="setColor(this);"></td>
</tr><tr>
<td width="20px" height="20px"
onclick="setColor2(this);"></td>
</tr></table>