The .nextUntil() traversing method collects following siblings up to a stop boundary — every sibling after the current element until (but not including) a matched selector, DOM node, or jQuery object. This tutorial covers the official definition-list demo, DOM-node stop with filter, comparisons with .nextAll(), and practical section-range patterns.
01
Stop boundary
Up to, not including
02
Selector stop
.nextUntil("dt")
03
DOM stop
Since jQuery 1.6
04
Filter arg
, "dd"
05
vs .nextAll()
Range vs all
06
Since 1.4
Core API
Fundamentals
Introduction
Sometimes you need siblings in a range — definitions under one term but not the next, list items until a separator, or table rows until a header row. .nextAll() grabs everything ahead; .nextUntil() stops at a boundary you define.
Available since jQuery 1.4 (DOM-node stop since 1.6), .nextUntil(stop [, filter]) walks forward through following siblings and halts before the first match of the stop argument. An optional filter narrows which siblings within that range are kept — ideal when terms and definitions share the same parent as mixed sibling types.
Concept
Understanding the .nextUntil() Method
Given a jQuery object representing a set of DOM elements, .nextUntil() examines each element’s following siblings in order. Siblings are added to the result until jQuery reaches one that matches the stop selector, DOM node, or jQuery object — that stop sibling is excluded. Siblings after the stop are never reached.
Think of it as a sliding window among siblings: start just after your element, end right before the stop. Without a stop or when the stop is never found, the window extends to the end — equivalent to .nextAll(). The second filter argument lets you keep only certain tags or classes within that window.
💡
Beginner Tip
$("#term-2").nextUntil("dt") selects definition dd elements for term 2 only — it stops before the next dt (term 3). The stop dt itself is never selected.
dd elements from term-1 through term-2 definitions → green text
(term-2 dt skipped by "dd" filter; term-3 excluded as stop)
How It Works
The DOM node #term-3 is the stop boundary. The "dd" filter keeps only definitions in the range — intermediate dt elements are skipped because they do not match the filter.
📈 Practical Patterns
Compare with .nextAll(), then apply stop boundaries in lists and tables.
Example 3 — .nextUntil() vs .nextAll() on the Same List
See how a stop boundary limits the range compared to selecting the full tail.
.nextUntil("li.stop") → red on item 4 only (stops before li.stop on item 5)
.nextAll() → blue on items 4 and 5
How It Works
Item 5 has class stop. .nextUntil("li.stop") from item 3 collects only item 4; item 5 is the excluded boundary. .nextAll() ignores the boundary and takes both.
Example 4 — List Items Until a Separator
Hide or style siblings in one section without affecting the next group.
Data rows after each group-head → .group-row
Next group-head row → stop boundary, not styled
How It Works
Each header row starts a range; the next header is the stop. Data rows between two tr.group-head elements get the class — a common grouped-table pattern without nested markup.
Applications
🚀 Common Use Cases
Definition lists — $("dt.term").nextUntil("dt") for definitions under one term.
Sectioned lists — items between .section-start and .section-end markers.
Grouped table rows — data rows until the next tr.group-head.
Wizard steps — steps in the current phase until a .phase-divider sibling.
Mixed sibling filter — .nextUntil(stop, "dd") when only one tag type matters in the range.
DOM-node boundary — stop at a known element reference from JavaScript.
🧠 How .nextUntil() Builds a Sibling Range
1
Start with source elements
jQuery object holds one or more DOM nodes.
Input
2
Walk forward sibling by sibling
Collect each following element sibling in order.
Traverse
3
Stop before boundary match
Halt when stop selector, DOM node, or jQuery object matches — exclude it.
Boundary
4
⋯
Filter & return
Apply optional filter — return bounded sibling set for chaining.
Important
📝 Notes
Available since jQuery 1.4 — DOM-node or jQuery stop since 1.6.
The stop element is never included — only siblings strictly before it in the chain.
If the stop is not found, behavior matches .nextAll() (with optional filter).
The optional filter applies to siblings within the range — not to the stop element.
Text nodes and comments between elements are skipped — element siblings only.
Mirror method: .prevUntil() — same range logic going backward.
Compatibility
Browser Support
.nextUntil() has been part of jQuery since 1.4+ (DOM stop since 1.6). It relies on standard sibling traversal with no browser-specific behavior beyond jQuery itself.
✓ jQuery 1.4+
jQuery .nextUntil()
Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. No native single-method equivalent — combine nextElementSibling loops or use .nextUntil() for clarity.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.nextUntil()Universal
Bottom line: Safe in any jQuery project. Use .nextUntil() for bounded sibling ranges; use .nextAll() when no stop boundary exists.
Wrap Up
Conclusion
The jQuery .nextUntil() method returns following siblings up to but not including a stop boundary. It fills the gap between .next() (one step) and .nextAll() (everything ahead) when your DOM has natural section markers.
Remember the official definition-list lesson: $("#term-2").nextUntil("dt") styles only term 2’s definitions. Pass a DOM node as the stop and a filter selector when mixed sibling types share the same parent.
Use clear stop markers in markup — dt, .section-end, header rows
Pass a filter when only one sibling type belongs in the range
Remember the stop element is excluded from results
Use DOM-node stop when you already hold an element reference
Compare with .nextAll() — range vs full tail
❌ Don’t
Expect the stop boundary inside the returned set
Use .nextUntil() when you need every following sibling — use .nextAll()
Assume the filter searches beyond the stop — range ends at the boundary
Confuse siblings with descendants — nested content needs .find()
Forget that a missing stop falls back to .nextAll() behavior
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .nextUntil()
Following siblings with a stop boundary.
5
Core concepts
⋯01
.nextUntil()
Until stop
API
✕02
Stop
Excluded
Boundary
→→03
.nextAll()
No stop
Compare
dd04
Filter
2nd arg
Filter
DOM05
Node stop
Since 1.6
API
❓ Frequently Asked Questions
.nextUntil() returns following siblings of each element in the current set, stopping before the first sibling that matches a selector, DOM node, or jQuery object. The stop element itself is never included. It defines a bounded range of siblings ahead — not the entire tail.
.nextAll() returns every following sibling with no stop point. .nextUntil(stop) returns siblings only until (but not including) the stop match. If no stop is supplied or the stop is never found, .nextUntil() behaves like .nextAll().
No. The element matched by the stop selector, DOM node, or jQuery object is excluded. Only siblings between the starting element and that stop boundary are returned.
Yes, since jQuery 1.6. Pass a raw DOM node or jQuery object as the first argument — for example nextUntil(document.getElementById('term-3')). The traversal stops before that element.
nextUntil(stop, filter) limits which siblings in the range are kept. Only elements between start and stop that also match the filter selector are included — useful when mixed sibling types sit in the same range.
jQuery collects all following siblings — the same result as .nextAll() with no filter. The range runs to the end of the sibling list because no stop boundary was encountered.
Did you know?
When jQuery added DOM-node and jQuery-object support to .nextUntil() in version 1.6, it matched the same upgrade given to .add(), .filter(), and other methods — letting you stop at an element you already selected instead of writing a new selector string for the boundary.