tags:

views:

128

answers:

2

I get color vlaue with jQuery with .css('color'), and then I know color that it should be. How can I compare colro value that I get from jQuery with for example black color value?

A: 

What about...

if ($('#element').css('color') == 'rgb(0, 0, 0)')
{
    // do something
}

Replace 0, 0, 0 with the red, green and blue values of the colour value you want to compare.

.css() jQuery API

Andy Shellam
Note that this won't always work for Internet Explorer, as it returns the original value. So it could be anything from a 3 or 6 digit hexadecimal value to a named color.
Bruce van der Kooij
Yeah I wasn't sure on that, but I thought jQuery abstracted out the browser differences?
Andy Shellam
A: 

HTML:

Javascript: $("#foo").css("color") == "black" // true

kinopyo