最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Loop in Jquery DataTable and change css only in specific rows - Stack Overflow

programmeradmin3浏览0评论

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;
  }
发布评论

评论列表(0)

  1. 暂无评论