By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,254 Members | 1,713 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,254 IT Pros & Developers. It's quick & easy.

Determining background color of a cell...

P: n/a
ehm
OK, I know that this sounds like a "newbie" question, but I have
searched the web with no luck.

How can I determine the background color of a cell in a table? I
have tried using all of the following:
obj.style.background
obj.style.bgColor
obj.bgColor
obj.style.color

However, all of these either return null or "undefined". Any help
would be greatly appreciated.
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ka****@earthlink.net (ehm) writes:
How can I determine the background color of a cell in a table? I
have tried using all of the following:
obj.style.background
obj.style.bgColor
obj.bgColor
obj.style.color However, all of these either return null or "undefined". Any help
would be greatly appreciated.


The style property corresponds to the style attribute in HTML. If you
haven't set the background color with the style attribute, it won't be
in the style property either.

What you want is the computed value of the background-color CSS property.
There are different ways to do that: The W3C DOM method and IE's method.

In IE, you can write

obj.currentStyle.backgroundColor

In W3C DOM (supported by Mozilla and Opera 7.2 (still in beta)), you
can write

document.defaultView.getComputedStyle(obj,"").back groundColor

There is no rule saying how the result is formatted. In Opera and
Mozilla, a white background is reported as "rgb(255, 255, 255)", while
IE6 says "white".

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.