I am trying to use JQuery to hide and show columns on an HTML table by clicking on a button. I can make all of my cells show and hide at once. How do I get just the column whos button I clicked on show and hide?
Here is the HTML I am using for the table:
<table width="500" border="1">
<tbody>
<tr align="center">
<td><input type="button" value="Show/Hide" /></td>
<td><input type="button" value="Show/Hide"/></td>
<td><input type="button" value="Show/Hide"/></td>
<td><input type="button" value="Show/Hide"/></td>
<td><input type="button" value="Show/Hide"/></td>
</tr>
<tr>
<th scope="col">Column 1</th>
<th scope="col">Column 2</th>
<th scope="col">Column 3</th>
<th scope="col">Column 4</th>
<th scope="col">Column 5</th>
</tr>
<tr class="columnMe">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="columnMe">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="columnMe">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="columnMe">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
And here is the JQuery I have so far:
$("document").ready(function() {
$( ":button" ).click(function() {
$('tr.columnMe td').toggle();
});
});
I would like to use THIS (pointing to the button I clicked) so that one function does the job instead of a function for each separate button.
All help appreciated!
Michael