I am trying to change background color on table cell depending on tp1_value.
tp1_value is selected cell value from database table and it is either True or False.
How do I make this so background-color become ‘green’ on true, ‘red’ on false? Default color is grey before I click table cell which is null value.
It doesn’t seem like I can use if statement on css. 🙁
<table class="t1">
<tr>
<td id="tp1"><div class="t"><label id="tp1_value"></label></div></td>
</tr>
</table>
#tp1_value {
background-color: grey;
}
let’s say that tp1_value is changeable with any condition, so you have to set your code as per the result,
here is a snippet shows the result in case the id is changeable between true and false.
You have to do that based on your server scripting language (that will talk to your db)
For example, you would create these 2 styles:
And the page would print the styles based on your server logic (ASP example below):
You need to use javascript to apply conditional logic.