Edit: My solution, based on the chosen answer:
var $brs,
$chunks = [];
$brs = $('hr:eq(1)').nextUntil($('hr:eq(2)')).filter('br');
$chunks.push($('hr:eq(1)').nextUntil($brs.eq(0)));
for (i = 0; i < $brs.length - 1; i++) {
$chunks.push($brs.eq(i).nextUntil($brs.eq(i+1)));
}
I have an unusual case that's resulted from a VERY poorly written website I am attempting to parse with javascript. I won't delve into the fun parsing, but I've finally managed to mangle it down to a meaningful structure. I now have a DOM that looks like this (for all intents and purposes, look at this as a flat listing of tags, each closed before the next starts):
<hr>
<a>
<span class="desc">
[<a>*] // 0 or more anchor tags can show up here
<br>
<br>
<a>
<span class="desc">
[<a>*]
<br>
<br>
.
.
.
What I am looking to do is grab each cluster of tags into its own array/jquery object/whatever by, essentially, running a .split() on the <br> tags. It is possible to do such a thing? if not, how would you go about separating this into chunks? So the result would be this:
[<a>, <span class="desc">, <a>],
[<a>, <span class="desc">],
[<a>, <span class="desc">, <a>, <a>, <a>],
[<a>, <span class="desc">],
...
i+1within the for-loop your index goes out of bounds on the very last case and.eq()will return an empty object; this means there's no stopping condition for the last.nextUntil()and everything (siblings) following the lastbrwill be pushed into the last index of$chunks(including the secondhr). Take a look at the array and you should notice that happening. If there's nothing following the lastbr, consider changing the loop condition toi<brs.length-1.