Reputation: 133
I have a table with 2 columns, I'm using PHP to generate dynamically rows to the table. Every table row have the following fields:
What I like to do is to hide the div containing the two inputs type text when the checkbox is checked, I tried to get the parent of the clicked checkbox using Jquery and then hide the corresponding div inside the currrent <tr>
but it's not working.
This is the HTML code to see how is my table generated:
<table>
<tr>
<th>Hide?</th>
<th>Inputs</th>
</tr>
<tr>
<td>
<input type="checkbox" name="checkBoxes[]">
</td>
<td>
<div class="two-inputs">
<input type="text" name="inputs[]">
<input type="text" name="inputs[]">
</div>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="checkBoxes[]">
</td>
<td>
<div class="two-inputs">
<input type="text" name="inputs[]">
<input type="text" name="inputs[]">
</div>
</td>
</tr>
Upvotes: 0
Views: 672
Reputation: 5699
$('input:checkbox').click(function() {
if (!$(this).is(':checked')) {
$(this).parent().next('.two-inputs').hide();
}
});
Upvotes: 0