JSFiddle - React, Tailwind, and code Playground

by thirdy_dot

HTML

<table border="1">
<tr>
 <th><button class="toggle" id="1">hide1</button></th>
  <th><button class="toggle" id="2">hide2</button></th>
  </tr>
  <tr>
  <td> <div>row 1, cell 1</div></td>
  <td><div>row 1, cell 2</div></td>
  </tr>
  <tr>
  <td><div>row 2, cell 1</div></td>
  <td> <div>row 2, cell 2</div></td>
  </tr>
  </table>

JavaScript

$(document).ready(function(){
    $("#1,#2").click(function(){
        var colid=$(this).prop("id");
        $("tr").children().each(function(){
            if (colid==1)
            {
               $(this).closest("td:nth-child(1),th:nth-child(1)").hide();                
            }
            else
            {
                $(this).closest("td:last-child,th:last-child").hide();
            }
            
        });
});
});