Mahesh Wagh
Mahesh Wagh

Reputation: 161

Changes Text Colors Via Jquery To Asp .Net Web Application

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

Answers (3)

mutiemule
mutiemule

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

PRASHANT
PRASHANT

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

Kathiravan
Kathiravan

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

Related Questions