JSFiddle - React, Tailwind, and code Playground

HTML

<table border="1" class="format2">
    <thead>
      <tr>
        <td>Col1</td>

        <td>Col2</td>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>row 1, cell 1</td>

        <td>row 1, cell 2</td>
      </tr>

      <tr>
        <td>row 2, cell 1</td>

        <td>row 2, cell 2</td>
      </tr>
    </tbody>
  </table>

  <table border="1" class="format2">
    <thead>
      <tr>
        <td>Col1</td>

        <td>Col2</td>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>row 1, cell 1</td>

        <td>row 1, cell 2</td>
      </tr>

      <tr>
        <td>row 2, cell 1</td>

        <td>row 2, cell 2</td>
      </tr>
    </tbody>
  </table>

JavaScript

$("table.format2 > thead").click(function(){
    $(this).next("tbody").toggle();
});