Reputation: 4691
I have a jQuery datatable row:
table = $('#reports').DataTable()
row = table.row(rowIndex)
How do I get the HTML class from it? (It is striped, and I want to find out if it is odd or even.)
I have tried:
row.hasClass('odd')
row.className
row.attr('class')
Any ideas?
Upvotes: 7
Views: 14237
Reputation: 85528
It is a really a good question. The ordinary jQuery way, by using row.index()
:
var rowClass = $("#example tbody tr:eq(" + row.index() + ")").attr('class');
Proof of concept -> http://jsfiddle.net/7jy46wz4/
Upvotes: 3
Reputation: 66
Taking what @rick-hitchcock said, another approach is to use the following code in validations:
var hasOddClass = $(row.node).hasClass("odd");
which, by the examples you gave, should be closer to what you want.
Upvotes: 0