The easiest way to do this is to add a class to each td that corresponds to the header class. When you click the button, it checks the class and then hides every td with that class. Since only s in this column will hide this class, it will effectively hide the column.
<table> <thead> <th>Name</th> <th>Address</th> </thead> <tbody> <tr> <td class="Name">Joe</td> <td class="Address">123 Main St. </tbody> </table>
And the script is something like:
$('th').click( function() { var col = $(this).html();
Something like that. This is probably more verbose than it should be, but it should demonstrate the principle.
Another way would be to simply calculate how many columns are above the question, and then scroll through each row and hide td, as well as that many columns. For example, if you want to hide the "Address" column, and this is column number 3 (index 2), then you will scroll through each row and hide the third (index 2).
Good luck ..
source share