0

Once use Chrome, console.log($("#some-element").css("background-color")), it returns rgba(255, 255, 255, 255), which means white, how I can check whether an element's background color is white?

Atul Arvind
  • 16,054
  • 6
  • 50
  • 58
coderz
  • 4,847
  • 11
  • 47
  • 70

3 Answers3

2

You could use the code described in How to get the background color code of an element? where the color's form is converted to its code. You could fetch the codes of the colors you would like compare and than compare the codes.

Community
  • 1
  • 1
nbanic
  • 1,270
  • 1
  • 8
  • 11
  • How to check whether an element defined ```background-color```? When use Chrome, it returns ```rgba(0,0,0,0)```, while when use Firefox, it returns ```transparent```. – coderz May 08 '14 at 07:42
  • @coderz As discussed in http://stackoverflow.com/questions/5380431/check-if-background-color-is-undefined I would see what value value is returned for each of the major browsers and hardcode its conversion to an appropriate more value. – nbanic May 08 '14 at 07:49
0

In JS

if (document.getElementById('someElementId').style.backgroundColor == "rgb(255, 255, 255)");

In JQuery

if($('#someElementId').css('background-color')=="rgb(255, 255, 255)") 
jhyap
  • 3,779
  • 6
  • 27
  • 47
-1

You can use:

if($("#some-element").css('background-color')=="rgb(255, 255, 255)") 
    console.log("White color detected");
Felix
  • 37,892
  • 8
  • 43
  • 55