I am trying to add a css class to the first tr of a table using jquery. I know this should be super easy, I found a lot of links and questions that provide correct solutions. Like these three and others:
How to get the id of first <tr> of <tbody> in HTML table using jQuery?
JQuery, select first row of table
How do I style the first row of every table on the page using jQuery
But for me none of these works.
I have a table with id DataTableMovimenti and I want to apply the css class "ct-active"
I tried the following instructions:
$("#DataTableMovimenti tr:first").addClass('ct-active');
$("#DataTableMovimenti").find("tr:first-children").addClass("ct-active");
$("#DataTableMovimenti").find("tr:first").addClass("ct-active");
$("#DataTableMovimenti").find("tr:eq(0)").addClass("ct-active");
$("#DataTableMovimenti").find("tbody tr:eq(0)").addClass("ct-active");
$("#DataTableMovimenti").children("tr:first").addClass("ct-active");
$("#DataTableMovimenti").closest('tr').addClass('ct-active');
I inserted the code in the $document.ready()
function in my jsp, because I want highlight the first row of the table when I enter the page.
The table have this structure:
<table id="DataTableMovimenti" class="table ct-datatables">
<thead>
<tr></tr>
............
</thead>
<tbody>
<tr id="tableRowId" class="table-row-tr"></tr>
...........
</tbody>
</table>
I want to change the css class of the first tr in the tbody section.