function func(id)
{
$(document).ready(function ()
{
$(".toggle").click(function ()
{
$("td:nth-child(" + id + ")>div").toggle();
});
});
return false;
}
Am attempting to hide the column corresponding to the button clicked. But this code gets some unexpected output like both the columns hiding when one button is clicked. where am i going wrong?
<table border="1">
<tr>
<th><button class="toggle" id="1" onclick="return func(this.id);" >hide</button></th>
<th><button class="toggle" id="2" onclick="return func(this.id);" >hide</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>