I get color value with jQuery with .css('color')
, and then I know color that it should be.
How can I compare color value that I get from jQuery with for example black color value?
The most common method would be a visual color comparison by looking at two physical color samples side by side under a light source. Color is very relative, so you can compare colors in terms of the other color across dimensions such as hue, lightness and saturation (brightness).
click(function() { var color = $( this ). css( "background-color" ); $( "p" ). html( "That div is " + color + "." ); });
Here is an approach that should work on all browsers using JQuery:
<div id="dummy" style="display:none;"></div>
on your HTML page. (Creating the dummy element dynamically with JQuery does not work for named colors)$('#dummy').css('color','black');
i.e.
if($('#element').css('color') === $('#dummy').css('color')) {
//do something
}
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