jqueryhtml-tablehidehtml-tbody

How to get row of second tbody in an HTML table


I have three tbody in a table an am able to hide first and second tr in first tbody using following code

$("table.ms-formtable tr:first").hide();
$("table.ms-formtable tr:nth-child(2)").hide();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<table class='ms-formtable'>
  <tbody>
    <tr>
    <td>tbody 1 row 1 cell 1</td>
    </tr>
    <tr>
    <td>tbody 1 row 2 cell 1</td>
    </tr>
  </tbody>
  <tbody>
    <tr>
    <td>tbody 2 row 1 cell 1</td>
    </tr>
    <tr>
    <td>tbody 2 row 1 cell 1</td>
    </tr>
  </tbody>
  <tbody>
    <tr>
    <td>tbody 3 row 1 cell 1</td>
    </tr>
    <tr>
    <td>tbody 3 row 1 cell 1</td>
    </tr>
  </tbody>
</table>

But how do I hide a certain tr in second tbody?


Solution

  • Maybe you can try to run the following:

    $("table.ms-formtable tbody:nth-child(2) tr:nth-child(2)").hide();
    

    The tbody:nth-child(2) specifies the 2nd tbody.