jquery select siblings 'until'
jQuery 1.4 now has the .nextUntil(selector) function:
$('div.parent').toggle(
function() {
$(this).nextUntil('div.parent').hide();
},
function() {
$(this).nextUntil('div.parent').show();
}
);
You can iterate through the nextAll
div
siblings elements until you find the following .parent
, check this example:
$('.parent').click(function() {
$(this).nextAll('div').each(function() {
if ($(this).is('.parent')) {
return false; // next parent reached, stop
}
$(this).toggleClass('highlight');
});
});
Markup used:
<div class="parent">parent 1</div>
<div class="child">child</div>
<div class="child">child</div>
<div class="parent">parent 2</div>
<div class="child">child</div>
<div class="parent">parent 3</div>
<div class="child">child</div>
<div class="child">child</div>
<div class="child">child</div>
...