Reputation: 21
<table id="main_table">
<tr style="background-color:green; color:white">
<td class="flip"> Section 1 </td>
</tr>
<tr>
<td>
<table class="section">
<tr>
<td>item 111</td>
<td>item 112</td>
<td>item 113</td>
<td>item 114</td>
</tr>
</table>
</td>
</tr>
</table>
$('.flip').click(function() {
$(this)
.closest('table')
.next('.section')
.toggle('fast');
});
Can someone help me to correct above code I tried slidetoggle but dunno why it is not working
thanks
Upvotes: 0
Views: 236
Reputation: 15387
Try this
$('.flip').on('click',function() {
$(this)
.closest('tr').next('tr')
.find('.section')
.toggle(200);
});
Upvotes: 0
Reputation: 148110
You can use tr
instead of table
to get the next row and use find()
to get .section
$('.flip').click(function() {
$(this)
.closest('tr')
.next('tr')
.find('.section')
.toggle('fast');
});
Upvotes: 1
Reputation: 388326
the section
element is a child of the next tr
element
$('.flip').click(function() {
$(this)
.closest('tr').next()
.find('.section')
.toggle('fast');
});
Demo: Fiddle
Upvotes: 0