with the following code I generate a table populating it with the data taken from a json file:
$(function() {
$.getJSON("Api/TabellaTempoMedio.php", function(data) {
$.each(data, function(index, row) {
$("#result").append("<tr>");
$.each(row, function(index2, column) {
$("#result").append("<td>" + column + "</td>");
});
$("#result").append("</tr>");
});
});
});
This is the Html code:
<table>
<thead>
<tr>
<th>Field1</th>
<th>Field2</th>
</tr>
</thead>
<tbody id="result">
</tbody>
</table>
but I cannot alternate the rows of the table with different colors. I tried this on CSS but it does not work:
tr:nth-child(odd) { background-color: grey; }
how can I do?