469,336 Members | 5,480 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Color reading

I need to extract the background color of a div in a format that can be
manipulated mathematically. When I retrieve style.backgroundColor, I
get rgb(255,255,255), even though it was put in as #FFFFFF. Is there a
way to get the hex value out of backgroundColor or pull the individual
color values out of the rgb()? I would prefer not parsing out the rgb()
string (mainly because I think that's just a sloppy way of doing it).

Sep 1 '05 #1
2 1292
Lee
ma*******@yahoo.com said:

I need to extract the background color of a div in a format that can be
manipulated mathematically. When I retrieve style.backgroundColor, I
get rgb(255,255,255), even though it was put in as #FFFFFF. Is there a
way to get the hex value out of backgroundColor or pull the individual
color values out of the rgb()? I would prefer not parsing out the rgb()
string (mainly because I think that's just a sloppy way of doing it).


var myRGB=style.background.color.match(/\d+/g)

seems cleaner than converting Hex characters to decimal.

Sep 1 '05 #2
ASM
ma*******@yahoo.com wrote:
I need to extract the background color of a div in a format that can be
manipulated mathematically. When I retrieve style.backgroundColor, I
get rgb(255,255,255), even though it was put in as #FFFFFF.


each browser makes its own cook ...

most use rgb(xxx,xxx,xxx)
other : #FFFFFF
and other : #ffffff
some returns strange values

I think, except if it is for you with only one browser,
you can't expect to get every time same combination

--
Stephane Moriaux et son [moins] vieux Mac
Sep 2 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Andy | last post: by
6 posts views Thread by Raymond Hettinger | last post: by
4 posts views Thread by Xah Lee | last post: by
21 posts views Thread by JoKur | last post: by
19 posts views Thread by jcrouse | last post: by
4 posts views Thread by Gaijinco | last post: by
21 posts views Thread by Naya | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.