I tried to log the actual result of the call:
$(this).css("background-color")
The result (on Chrome) was: rgb(255,255,255)
hence it is different from the string "#FFFFFF"
.
Also the problem with the counter
is that when it's an odd number you set the background-color to red, when it's an even number the background-color is red [returning rgb(255,0,0)
] and thus it's different from "#FFFFFF"
.
Here's a Fiddle.
I'd suggest you using a different kind of match.. for instance you could toggle classes on click and use the added classes selector to alter the background-color
Using classes instead of $(this).css(..) == "a color string"
inside the IF
condition means that you can create a .white
class which your item has at the start. When clicked, if it has .white
class than you change its color using another class .red
(class names are examples, just name them as you wish)
The classes are set to only change the background-color
in your CSS file, hence they'll be something like:
.white{
background-color: #FFFFFF
}
.red{
background-color: #FF0000
}