Akash Akash - 1 month ago 9
jQuery Question

Jquery comparing background color

I am using:

var element = $(this).parents("tr:first");

if (element.css("background-color")=="black)")
element.animate({ backgroundColor: "white" }, 1000);
else
element.animate({ backgroundColor: "black" }, 1000);


To change background color, but comparision seems to fail, I also tried:

if (element.css("background-color")==rgb(0,0,0))


But the if condition seems to return false everytime?

Answer

the returned value is in rgb format, you should use quotation marks for strings:

if(element.css("background-color") == "rgb(0, 0, 0)")