I have rows I want to show and hide, but only up until the next first-level row. My code is toggling all of the second-level rows instead of the ones up until the next first-level row.
When you click on a row with the class "first-level", I would like every row with the class "second-level" up until the next instance of "first-level" to toggle.
<table>
<tbody>
<tr class="first-level">
<td>First Level</td>
<td>First Level</td>
<td>First Level</td>
<td>First Level</td>
<td>First Level</td>
</tr>
<tr class="second-level">
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
</tr>
<tr class="second-level">
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
</tr>
<tr class="second-level">
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
</tr>
<tr class="first-level">
<td>First Level</td>
<td>First Level</td>
<td>First Level</td>
<td>First Level</td>
<td>First Level</td>
</tr>
<tr class="second-level">
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
</tr>
<tr class="second-level">
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
</tr>
<tr class="second-level">
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
<td>Second Level</td>
</tr>
</tbody>
</table>
js:
var firstLevel = $('.first-level')
var secondLevel = $('.second-level')
$(firstLevel).click(function() {
$(secondLevel).nextUntil(firstLevel).toggle("slow");
});