How can I compare two color values in jQuery/JavaScript?

后端 未结 6 1872
耶瑟儿~
耶瑟儿~ 2020-12-06 16:05

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

6条回答
  •  星月不相逢
    2020-12-06 16:54

    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

提交回复
热议问题