Reputation: 66650
I have html like this:
<ul>
<li class="foo">One</li>
<li class="bar">Two</li>
<li class="bar">Tree</li>
<li class="bar">Four</li>
<li class="foo">Five</li>
<li class="bar">Six</li>
<li class="bar">Seven</li>
</ul>
and I have JS code like this:
$('.foo').click(function() {
$(this).allNext('.bar');
});
How can I select all elements that are after .foo and have class bar.
Upvotes: 1
Views: 59
Reputation: 24001
beside nextAll may be you want to know about nextUntil() .. it will select all .bar until the next .foo
$('.foo').click(function() {
$(this).nextUntil('.foo').css('background','red');
});
Upvotes: 0
Reputation: 4572
You can use nextAll:
$('.foo').click(function() {
$(this).nextAll('.bar');
});
Upvotes: 2