1

I assign an element's background color using a hex code.

e.style.backgroundColor = '#7bf47e'

When I come back later to ASK for that color, so I can see if it's changed or not, Chrome gives me an RGB() triplet: rgb(123,123,123).

Since '#7bf47e' does not equal 'rgb(123,123,123)', the color has always changed as far as Chrome is concerned.

IE10 handles this fine, giving me '#7bf47e' when I ask for the background color.


EDIT: Sorry, here's a clarification. The actual rgb values below are purely for example. I didn't note what the actual rgb() values were. I'm just saying that I give it a hex, and it gives me back an rbg(). I'd like to get it back in the same format I set it.

KWallace
  • 1,570
  • 1
  • 15
  • 25
  • Are you saying Chrome gives you a completely random RGB triplet every time you ask for it? – BoltClock Jul 30 '14 at 15:42
  • You mention `rgb(123,123,123)` and `rgb(1,2,3)`, which is it? – Ben Jul 30 '14 at 15:42
  • Are you sure you're clicking on the correct element? Also, in Chrome you can always shift-click on the color swatch next to a color in dev tools to switch between `rgb`, hex, and `hsl`. – Ryan Mitchell Jul 30 '14 at 15:43
  • Sorry, guys. My bad. The actual rgb values are purely for example. I didn't note what the actual rgb() values were. I'm just saying that I give it a hex, and it gives me back an rbg(). I'd like to get it back in the same format I set it. – KWallace Jul 30 '14 at 18:48
  • It doesn't seem to be consistent across browsers, but workarounds exist for taking the RGB triplet and converting to hex manually. See http://stackoverflow.com/questions/1740700/how-to-get-hex-color-value-rather-than-rgb-value – BoltClock Jul 30 '14 at 18:50

2 Answers2

0

#7BF47E is equal to rgb(123, 244, 126)

whereas rgb(123, 123, 123) is #7B7B7B

it seems like chrome changed background color you set.

blurstream
  • 429
  • 3
  • 13
0

It appears that the browser represents all colors internally as RBG() triplets.

So, even if you set a hexadecimal color, or even a color name, internally to Chrome it will be converted to rgb(nnn,nnn,nnn). This behaviour is by design, and you simply have to anticipate and work with that.

KWallace
  • 1,570
  • 1
  • 15
  • 25