The .prevUntil() traversing method collects preceding siblings up to a stop boundary — every sibling before 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 .prevAll(), and practical section-range patterns.
01
Stop boundary
Up to, not including
02
Selector stop
.prevUntil("dt")
03
DOM stop
Since jQuery 1.6
04
Filter arg
, "dd"
05
vs .prevAll()
Range vs all
06
Since 1.4
Core API
Fundamentals
Introduction
Sometimes you need siblings in a range going backward — definitions before one term but not the previous heading, list items until a separator, or table rows until a header row. .prevAll() grabs everything behind; .prevUntil() stops at a boundary you define.
Available since jQuery 1.4 (DOM-node stop since 1.6), .prevUntil(stop [, filter]) walks backward through preceding 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 .prevUntil() Method
Given a jQuery object representing a set of DOM elements, .prevUntil() examines each element’s preceding siblings in order (closest first). 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 before the stop are never reached beyond the boundary.
Think of it as a sliding window among siblings: start just before your element, end right before the stop. Without a stop or when the stop is never found, the window extends to the beginning — equivalent to .prevAll(). The second filter argument lets you keep only certain tags or classes within that window.
💡
Beginner Tip
$("#term-2").prevUntil("dt") selects definition dd elements for term 1 only — it stops before the previous dt (term 1). The stop dt itself is never selected.
dd elements from term-2 and term-1 definitions → green text
(term-2 dt skipped by "dd" filter; term-1 excluded as stop)
How It Works
The DOM node #term-1 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 .prevAll(), then apply stop boundaries in lists and tables.
Example 3 — .prevUntil() vs .prevAll() on the Same List
See how a stop boundary limits the range compared to selecting the full preceding tail.
.prevUntil("li.stop") → red on items 3 and 4 only (stops before li.stop on item 2)
.prevAll() → blue on items 1, 2, 3, and 4
How It Works
Item 2 has class stop. .prevUntil("li.stop") from item 5 collects only items 4 and 3; item 2 is the excluded boundary. .prevAll() ignores the boundary and takes all four preceding items.
Example 4 — List Items Preceding Until a Separator
Hide or style siblings in one section without affecting the previous group.
Data rows before each group-head → .group-row
Previous group-head row → stop boundary, not styled
How It Works
Each header row ends a range going backward; the previous 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").prevUntil("dt") for definitions under the previous term.
Sectioned lists — items between .section-start and .section-end markers.
Grouped table rows — data rows until the previous tr.group-head.
Wizard steps — steps in the current phase until a .phase-divider sibling.
Mixed sibling filter — .prevUntil(stop, "dd") when only one tag type matters in the range.
DOM-node boundary — stop at a known element reference from JavaScript.
🧠 How .prevUntil() Builds a Sibling Range
1
Start with source elements
jQuery object holds one or more DOM nodes.
Input
2
Walk backward sibling by sibling
Collect each preceding element sibling in order (closest first).
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 .prevAll() (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: .nextUntil() — same range logic going forward.
Compatibility
Browser Support
.prevUntil() 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 .prevUntil()
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 previousElementSibling loops or use .prevUntil() 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
.prevUntil()Universal
Bottom line: Safe in any jQuery project. Use .prevUntil() for bounded sibling ranges; use .prevAll() when no stop boundary exists.
Wrap Up
Conclusion
The jQuery .prevUntil() method returns preceding siblings up to but not including a stop boundary. It fills the gap between .prev() (one step) and .prevAll() (everything behind) when your DOM has natural section markers.
Remember the official definition-list lesson: $("#term-2").prevUntil("dt") styles only term 1’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-start, 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 .prevAll() — range vs full tail
❌ Don’t
Expect the stop boundary inside the returned set
Use .prevUntil() when you need every preceding sibling — use .prevAll()
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 .prevAll() behavior
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .prevUntil()
Preceding siblings with a stop boundary.
5
Core concepts
⋯01
.prevUntil()
Until stop
API
✕02
Stop
Excluded
Boundary
←←03
.prevAll()
No stop
Compare
dd04
Filter
2nd arg
Filter
DOM05
Node stop
Since 1.6
API
❓ Frequently Asked Questions
.prevUntil() returns preceding 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 behind — not the entire preceding tail.
.prevAll() returns every preceding sibling with no stop point. .prevUntil(stop) returns siblings only until (but not including) the stop match. If no stop is supplied or the stop is never found, .prevUntil() behaves like .prevAll().
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 prevUntil(document.getElementById('term-1')). The traversal stops before that element.
prevUntil(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 preceding siblings — the same result as .prevAll() with no filter. The range runs to the start of the sibling list because no stop boundary was encountered.
Did you know?
.prevUntil() and .nextUntil() were added together in jQuery 1.4 as mirror-image range selectors — one walks backward through preceding siblings, the other forward through following siblings, both stopping before a boundary element. When DOM-node stops arrived in 1.6, both methods gained the same upgrade.