Akash Akash - 1 year ago 91
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);
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 Source

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

if(element.css("background-color") == "rgb(0, 0, 0)")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download