Your generous donation allows me to continue developing and updating my code!
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 prevUntil example, with an "until" selector
- List item with a class of "a"
- List item with a class of "b"
- List item with a class of "c"
- List item with a class of "d"
- List item with a class of "e"
- List item with a class of "f"
The code
$(function(){ // Example 1: From .g, select all previous sibling elements until .a $('#ex1 .f').prevUntil('.a').addClass('selected'); });
A more complex prevUntil 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 .f, select all previous sibling 'p' elements until .a $('#ex2 .f').prevUntil('.a', 'p').addClass('selected'); });