Determining background color of a cell...

E

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.
 
L

Lasse Reichstein Nielsen

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,"").backgroundColor

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top