You're getting the RGB value rather than the color name
when i used var look = $('#sw').css('color'); the result was "rgb(255, 0, 0)" in the chrome debugger
Your code isn't working because the string returned is the rgb value of colour, rather than the color itself, replacing the names with RGB values fixeds your code.
<script type="text/jscript">
window.setInterval(function () {
if ($('#sw').css('color') === 'rgb(255, 0, 0)') {
$("#sw").css("color", "rgb(0, 0, 255)");
}
else if ($("#sw").css("color") === "rgb(0, 0, 255)") {
$("#sw").css("color", "rgb(0, 128, 0)");
}
else if ($("#sw").css("color") === "rgb(0, 128, 0)") {
$("#sw").css("color", "rgb(255, 0, 0)");
}
}, 1000);
</script>
As noted in the second related question, this won't worrk on IE. because IE uses hex values. I suggest using another else statement to account for that. something like
else if ($("#sw").css("color") === "#FF0000") {
$("#sw").css("color", "#00FF00");
}
either that or using an or condition on your basic statements like
if ($('#sw').css('color') === 'rgb(255, 0, 0)')||($("#sw").css("color") === "#FF0000") {
$("#sw").css("color", "rgb(0, 0, 255)");
}
I imagine that it works in Firefox because firefox will store the css color property however you specify it, however chrome will normalise the css into an RGB value, though i may be wrong
Also, you may be able to make it more efficient by using straigt javascript. something like: How to get the background color of an element using javascript?
Related Questions:
Jquery if then statement for css value
How to get hex color value rather than RGB value?