How do you change background color on td in CSS?

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;
}

14 thoughts on “How do you change background color on td in CSS?”

Leave a Comment