Reputation: 161
I want to make changes in text colors which is in tag as below.
Note:- The below example is of content page hence jquery is link to master page.
<script type="text/jscript">
window.setInterval(function(){
if($("#sw").css("color","Red")){<!—text color in Span Tag-->
$("#sw").css("color","Blue");
}
else if($("#sw").css("color","Blue")){
$("#sw").css("color","Red");
}
},1000);
</script>
The above example changes my text colors from Red To Blue but it’s not changes from blue to red as per second condition in jquery. What’s The Problem?.
Upvotes: 0
Views: 457
Reputation: 2549
Try this:
<script type="text/jscript">
window.setInterval(function(){
if ($("#sw").css("color") == "Red") {
$("#sw").css("color","Blue");
} else if($("#sw").css("color") == "Blue") {
$("#sw").css("color","Red");
}
}, 1000);
</script>
Basically you are trying to set the color in the if statement. You should instead check, not set.
Upvotes: 3
Reputation: 11
<script type="text/jscript">
window.setInterval(
function () {
$("#sw").css("color",
($("#sw").css("color").trim() == "rgb(0, 0, 255)") ? "rgb(0, 255, 0)" : "rgb(0, 0, 255)"
);
}, 500);
</script>
Upvotes: 0
Reputation: 699
You are trying to set the color now check this fiddle http://jsfiddle.net/tRzAb/
setInterval(function(){
if($("#sw").css("color") == "rgb(0, 0, 255)"){
$("#sw").css("color","Red");
}
else{
$("#sw").css("color","Blue");
}
},1000);
Upvotes: 1