.nextUntil([selector|element] [, filter]) (since jQuery 1.4; DOM/jQuery stop since 1.6) returns following siblings up to — but not including — a stop boundary. An optional second filter keeps only matching elements in that range. Returns a new jQuery object; does not change the DOM.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$("#term-2").nextUntil("dt"); // dd's until next dt
$("#term-1").nextUntil(term3, "dd"); // dd only, stop at DOM node
$("li.start").nextUntil(".end"); // items before .end
$("li.start").nextUntil(); // same as .nextAll()
// next() → one sibling
// nextAll() → all following (no stop)
// nextUntil() → following until stop (exclusive)
Call
What it does
Matched set
Starting element(s)
Stop (selector / node)
Where to stop (exclusive). Omit → like .nextAll()
filter
Keep only matching siblings in the range
Return value
New jQuery set (0 or more)
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
selector / node
Used in Stop (selector / node). Where to stop (exclusive). Omit → like .nextAll()
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
Example 1 — Official: .nextUntil("dt")
From term 2, mark every sibling until the next term (jQuery API demo).
.nextUntil("dt") → 3 dd's only
.nextAll() → 3 dd's + term 3 + later dd's
How It Works
Until. Stops before the next dt.
All. Keeps walking past later terms.
Same start. Both begin at term 2.
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.
.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 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 start and that boundary are returned.
Yes, since jQuery 1.6. Pass a DOM node or jQuery object as the first argument — for example nextUntil(document.getElementById("term-3")). Traversal stops before that element.
nextUntil(stop, filter) keeps only siblings in the range that also match the filter — useful when mixed sibling types sit between start and stop.
No. Like other jQuery traversing methods, it only queries the existing DOM and returns a new collection.