jQuery .nextUntil() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Traversing

Definition

.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)
CallWhat it does
Matched setStarting element(s)
Stop (selector / node)Where to stop (exclusive). Omit → like .nextAll()
filterKeep only matching siblings in the range
Return valueNew jQuery set (0 or more)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
selector / nodeUsed in Stop (selector / node). Where to stop (exclusive). Omit → like .nextAll()

Return Value

Return ValueDescription
jQuery objectMost 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).

jQuery
$("#term-2").nextUntil("dt").append(" [until]");
Try It Yourself

How It Works

  1. Start. Select #term-2.
  2. Walk. Collect following siblings one by one.
  3. Stop. Halt when the next dt is reached — do not include it.

Example 2 — DOM Stop + "dd" Filter

Official idea: stop at a DOM node and keep only dd siblings.

jQuery
var term3 = document.getElementById("term-3");

$("#term-1")
  .nextUntil(term3, "dd")
  .append(" [dd]");
Try It Yourself

How It Works

  1. DOM stop. Pass the raw #term-3 element (since 1.6).
  2. Range. Walk from term 1 until that node.
  3. Filter. Keep only siblings matching "dd".

Example 3 — .nextUntil() vs .nextAll()

Same start — bounded range versus every following sibling.

jQuery
$("#u-term-2").nextUntil("dt").append(" [until]");
$("#a-term-2").nextAll().append(" [all]");
Try It Yourself

How It Works

  1. Until. Stops before the next dt.
  2. All. Keeps walking past later terms.
  3. 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.

Next: .prev() Method — Previous Sibling

Get the immediate previous sibling — the reverse of .next().

.prev() Method — Previous Sibling tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful