I want to find out if a DOM Element has a style which is for example a color:Red. If this is defined on the inline style just like
<input type="text" style="color:Red">
I can get it easily with JavaScript
But how about if it's defined on a role - I mean as a css class and assign the class to the DOM Element
With javascript I know I can get the color with some method call computedStyle and give it the name of the property but it brings me the color in RGB numbers mode in Firefox and in IE it gets the color name
my question here is how to convert RGB into a simple color name?
Source => Target = (BGColor + Source) = Target. R = ((1 - Source. A) * BGColor. R) + (Source.
Colors are typically expressed through hexadecimal codes, either prefixed using a pound sign ( # ) or 0x to denote base 16 values. Combining these channels together, we end up with RGB codes, such as: 0xff0000 — Red. 0x00ff00 — Green.
Here is the library that will do it: Name That Color - http://chir.ag/projects/name-that-color/
There's a sample function you could call in this answer:
Javascript function to convert color names to hex codes
It does a conversion from the name to the hex value.
I think that these are the names supported in most browsers, you could store them in a dictionary and look them up: http://www.febooti.com/products/iezoom/online-help/html-color-names-x11-color-chart.html
The x11 color names are a superset of the ones defined in css.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With