Reputation: 28837
What is the best way to get all next siblings of a element? Not just next one and not siblings before it?
This was the way I found, but is there a jQuery selector for it?
$('.someclass').click(function () {
var chosenOne = $(this);
$('.someclass').removeClass('extraclass');
chosenOne.parent().find('.someclass').each(function () {
var el = $(this).index();
if (el >= chosenOne.index()) {
$(this).addClass('extraclass');
}
});
});
Upvotes: 0
Views: 172
Reputation: 95022
the .nextAll() method was made for this:
chosenone.nextAll(".someclass").addBack().addClass("extraclass")
Upvotes: 4