Reputation: 1745
I have the following HTML code:
<tr class="rowMain"></tr> --> if I click on this I should get the 2 <tr> below
<tr></tr>
<tr></tr>
<tr class="rowMain"></tr> --> if I click on this I should get the 3 <tr> below
<tr></tr>
<tr></tr>
<tr></tr>
and so on
What I want to select is the <tr>
elements that are between each rowMain class? what is the best way
I tried the following code in JQuery:
$('.main').click(function(){
$(this).nextAll('tr').not('.rowMain');
});
But this is selecting All element after the click element what is the best way to do this?
Upvotes: 0
Views: 118
Reputation: 36
$('.rowMain').click(function(){
$(this).nextUntil('.rowMain', 'tr').hide();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr class="rowMain"><td>test</td></tr>
<tr><td>1</td></tr>
<tr><td>1</td></tr>
<tr class="rowMain"><td>test2</td></tr>
<tr><td>2</td></tr>
<tr><td>2</td></tr>
<tr><td>2</td></tr>
</table>
Upvotes: 2