I am looking to dynamically change the row color based on the content of a <td>
tag using only HTML, CSS, or JS within my current application setup that does not support external src. Below is the code snippet:
table {
width: 750px;
border-collapse: collapse;
margin:20px auto;
}
tr:nth-of-type(even) {
background: #eee;
}
tr:hover {
background-color:#f5f5f5;
}
th {
background: #1489b8;
color: white;
font-weight: default;
}
td, th {
padding: 10px;
border: 3px solid #ccc;
text-align: center;
font-size: 15px;
}
h3, p{
text-align: center;
}
<head>
<h3>Hi User,</h3>
<p>An alert is created. Following are the details.</p>
</head>
<table style="width:100%">
<thead>
<tr>
<th> Description</th>
<td>working</td>
</tr>
<tr>
<th>Parameter</th>
<td>Shutdown</td>
</tr>
<tr>
<th>Machine </th>
<td>ABC</td>
</tr>
<tr>
<th> Type</th>
<td>Sensor Machine</td>
</tr>
<tr>
<th> Severity</th>
<td>Low</td>
</thead>
</table>
In the above example, when the last <td>
tag contains the text "Low", I want the row color to change to green. If it contains "Medium", the color should change to yellow. Is there any way to achieve this?