Page 1 of 1

[SOLVED] JavaScript style.backgroundColor gives RGB values

Posted: Sat Feb 05, 2005 5:36 pm
by Chris Corbyn
Hi,

I really need the hex code of the background color of an element but when outputting

Code: Select all

el.style.backgroundColor
in netscape/mozilla I get RGB(int,int,int) .... but in IE I get the hex code exactly the way it looks in the style tags.

Why does netscape do this and how can I get around it?

Cheers

Posted: Sat Feb 05, 2005 7:18 pm
by feyd
should probably either create a function to parse the information, as I don't see any functions to request it being in any other form (outside of an object which requires newer interpreter I believe..)

Posted: Sat Feb 05, 2005 7:33 pm
by Chris Corbyn
I've just this minute before I checked your post done a pattern match, followed by parseInt and toString(16) to do it. Not too sure why mozilla show the values like this when they're not generally used in HTML coding.

Cheers

Posted: Sat Feb 05, 2005 7:36 pm
by feyd
you have to remember this data is coming from the style sheet objects.. which is not normal html coding ;)