[SOLVED] JavaScript style.backgroundColor gives RGB values

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

[SOLVED] JavaScript style.backgroundColor gives RGB values

Post 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
Last edited by Chris Corbyn on Mon Feb 07, 2005 5:14 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you have to remember this data is coming from the style sheet objects.. which is not normal html coding ;)
Post Reply