title: Jquery add css class to the first row of a table
body: <p>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:</p>
  <p><a href="https://stackoverflow.com/questions/23465602/how-to-get-the-id-of-first-tr-of-tbody-in-html-table-using-jquery">How to get the id of first &lt;tr&gt; of &lt;tbody&gt; in HTML table using jQuery?</a></p>
  <p><a href="https://stackoverflow.com/questions/6924333/jquery-select-first-row-of-table">JQuery, select first row of table</a></p>
  <p><a href="https://stackoverflow.com/questions/12938510/how-do-i-style-the-first-row-of-every-table-on-the-page-using-jquery">How do I style the first row of every table on the page using jQuery</a></p>
  <p>But for me none of these works.</p>
  <p>I have a table with id DataTableMovimenti and I want to apply the css class &quot;ct-active&quot;</p>
  <p>I tried the following instructions:</p>
  <pre><code>$(&quot;#DataTableMovimenti tr:first&quot;).addClass('ct-active');
  $(&quot;#DataTableMovimenti&quot;).find(&quot;tr:first-children&quot;).addClass(&quot;ct-active&quot;);
  $(&quot;#DataTableMovimenti&quot;).find(&quot;tr:first&quot;).addClass(&quot;ct-active&quot;);
  $(&quot;#DataTableMovimenti&quot;).find(&quot;tr:eq(0)&quot;).addClass(&quot;ct-active&quot;);
  $(&quot;#DataTableMovimenti&quot;).find(&quot;tbody tr:eq(0)&quot;).addClass(&quot;ct-active&quot;);
  $(&quot;#DataTableMovimenti&quot;).children(&quot;tr:first&quot;).addClass(&quot;ct-active&quot;);
  $(&quot;#DataTableMovimenti&quot;).closest('tr').addClass('ct-active');
  </code></pre>
  <p>I inserted the code in the <code>$document.ready()</code> function in my jsp, because I want highlight the first row of the table when I enter the page.</p>
  <p>The table have this structure:</p>
  <pre><code>&lt;table id=&quot;DataTableMovimenti&quot; class=&quot;table ct-datatables&quot;&gt;
  &lt;thead&gt;
     &lt;tr&gt;&lt;/tr&gt;
        ............
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr id=&quot;tableRowId&quot; class=&quot;table-row-tr&quot;&gt;&lt;/tr&gt;
        ...........
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  <p>I want to change the css class of the first tr in the tbody section.</p>