With jQuery Untils you easily traverse forward along next siblings, backwards along previous siblings, and upwards along parents, selecting all elements (or just elements that match an optional selector).

A simple nextUntil example, with an "until" selector

  1. List item with a class of "a"
  2. List item with a class of "b"
  3. List item with a class of "c"
  4. List item with a class of "d"
  5. List item with a class of "e"
  6. List item with a class of "f"

The code

$(function(){
  
  // Example 1: From .a, select all next sibling elements until .f
  $('#ex1 .a').nextUntil('.f').addClass('selected');
  
});

A more complex nextUntil example, with both an "until" and "each" selector

Paragraph with a class of "a"

Span with a class of "b"

Paragraph with a class of "c"

Span with a class of "d"

Paragraph with a class of "e"

Span with a class of "f"

The code

$(function(){
  
  // Example 2: From .a, select all next sibling 'p' elements until .f
  $('#ex2 .a').nextUntil('.f', 'p').addClass('selected');
  
});