A.N.B Akhilesh
A.N.B Akhilesh

Reputation: 211

How to change colour in CSS, by giving condition?

I'm having a body. In that there is one field "status". If status=OK background should be white color. If status=error, background should get red. Please tell me how to give the condition in CSS file.

Body code in CSS

This is the GUI

Upvotes: 2

Views: 6024

Answers (2)

ANR Upgraded Version
ANR Upgraded Version

Reputation: 949

Try this Jquery Code

$( "#status" ).change(function() {
   if($(this).val() == "OK")
     {
      $("body").css("background-color","white");
     }
  else 
    {
     $("body").css("background-color","red");
    }
});

Working Demo Here

Upvotes: 1

Dev D
Dev D

Reputation: 225

You can use jquery method to do so. Try the following:

var status =  $("[id$=lblStatus]").val()

if(status == "Ok")
{
  $jQuery("body").css("background-color","White");
}
else if (status == "Error")
{
  $jQuery("body").css("background-color","Gray");
}

Upvotes: 1

Related Questions