My current code is designed to change the background color of td elements for odd and even rows. However, when a new high score is entered, a new td is added but it does not get colored automatically as intended.
I am facing an issue where the code is not behaving as shown in the provided screenshot. Can anyone suggest a solution?
https://i.stack.imgur.com/zCFEE.png
th {
height: 30px;
margin-top: 15px;
background-color: white;
}
tr {
background-color: #fff;
padding: 20px;
font-size: 20px;
}
tr:nth-child(even) {
background: #f3f1f1
}
<table id="scoreboard" CELLSPACING=0 CELLPADDING=5>
<tr>
<th>Name</th>
<th>Score</th>
</tr>
<tr>
<td>AAA </td>
<td>1</td>
</tr>
<tr>
<td>BBB </td>
<td>2</td>
</tr>
<tr>
<td>CCC </td>
<td>3</td>
</tr>
</table>