I am attempting to apply a css class to the initial tr element within a table using jQuery. While I have come across various solutions and resources that seem promising, such as the following references:
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
None of these solutions have been successful for me.
The table I am working with has the id of DataTableMovimenti, and I am trying to assign the css class "ct-active".
I have experimented with the following commands:
$("#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 have placed this code within the $document.ready()
function in my jsp file to ensure that the first row of the table is highlighted upon page load.
The structure of the table is as follows:
<table id="DataTableMovimenti" class="table ct-datatables">
<thead>
<tr></tr>
............
</thead>
<tbody>
<tr id="tableRowId" class="table-row-tr"></tr>
...........
</tbody>
</table>
My goal is to modify the css class of the initial tr element within the tbody section of the table.