I need to loop inside my Datatable, and I want to change background-color attribute only in some rows at specific index, so I need to have control over the index of the table.
My idea is to extract a single tr on a specific position, so I was trying to write this code, I don't have any error in console, I see it prints the correct number of index for each row, but nothing happen on the table, the css is not applied.
var myTable = $('#food').DataTable();
$('#button').on('click', function () {
$('#food > tbody > tr').each(function(index, tr) {
console.log(index);
$("#food tr:nth-child("+index+")").addClass('change-color');
});
});
.change-color{
background-color: #FFFFAC;
}