Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert css system colors to hex with javascript?

Is it possible to get the hex or rgb values of the color names for these colors?

http://artific.com/library/css-2-system-colors.html

Say for example that I set a div to use "windowFrame" as the background color. Could I use:

https://developer.mozilla.org/en/DOM/window.getComputedStyle somehow?

like image 647
Justin Avatar asked Sep 28 '26 04:09

Justin


1 Answers

getComputedStyle seems to work.

Firebug Output (working on http://artific.com/library/css-2-system-colors.html) :

var t = document.getElementsByClassName("window")[0]; window.getComputedStyle(t).backgroundColor;
"rgb(255, 255, 255)"

>>> var t = document.getElementsByClassName("menu")[0]; window.getComputedStyle(t).backgroundColor;
"rgb(240, 240, 240)"

>>> var t = document.getElementsByClassName("info")[0]; window.getComputedStyle(t).backgroundColor;
"rgb(225, 225, 225)"
like image 116
Eliu Avatar answered Sep 29 '26 20:09

Eliu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!