The adjacent sibling combinator prev + next selects elements matching next that are immediately preceded by a sibling matching prev. Both sides must share the same parent. Available since jQuery 1.0 (standard CSS).
Remember
$("prev + next")
$("label + input") → input right after a label
$("h2 + p") → first p after each h2 only
$("h2 ~ p") → all following sibling p (general)
$("div input") → input nested inside div (descendant)
$("div > input") → direct child input (child)
Name the previous sibling, add +, then name the element that must sit right after it.
Confirm both elements are siblings under the same parent.
Write $("prev + next") — for example $("label + input").
Chain a method: .val(), .addClass(), events, and so on.
If you need every following match, use ~ instead of +.
Piece
Required?
Role
prev
Yes
Selector for the preceding sibling
+
Yes
Adjacent sibling combinator
next
Yes
Selector for the immediate next sibling
Pseudocode
Pseudocode
for each element E matching "next":
P = E.previousElementSibling
if P exists and P matches "prev":
and P.parent === E.parent:
keep E
return jQuery(kept elements)
Reference
Cheat Sheet
Keep these facts handy while writing adjacent sibling selectors.
Topic
Detail
Syntax
$("prev + next")
Meaning
Immediate next sibling only
Parent rule
Both sides must share the same parent
vs ~
+ = one; ~ = all following
vs space
Sibling relationship, not nesting
vs .next()
Selector vs traversal method
Since
jQuery 1.0 (standard CSS)
Try it
Live Preview
Pick a combinator against a small sample DOM and see which nodes match.
Sample markup mirrors the official label + input pattern plus sibling contrasts.
+: 1
~: 3
+ = immediate only; ~ = all following siblings
How It Works
Plus stops at one. Only the first p after h2 matches +.
Tilde continues. Every later sibling p still matches ~.
Same parent required. Both combinators need siblings under one parent.
Pick by intent. Lead line → +. Rest of the section → ~.
Example 4 — Sibling + vs Descendant Space
Adjacent siblings are not the same as nested descendants.
jQuery
console.log("span + input:", $("span + input").length);
console.log("div input:", $("div input").length);
// + → input immediately after a span sibling
// space → any input nested inside a div
true
2
Same adjacent inputs via + and .next("input")
How It Works
Selector path.$("label + input") queries the document in one string.
Traversal path. Start from labels, then take each immediate next sibling if it is an input.
Same set. Lengths match when every label is followed by an input.
When to choose. Static query → +. Already holding labels → .next().
Edge Cases & Pitfalls
Check these before relying on + in real projects.
trap
Anything between breaks +
A whitespace-only text node is ignored by browsers for previousElementSibling, but an element (even an empty <span>) between label and input prevents a match.
parent
Must share the same parent
Official docs: both sides of + (and ~) must be siblings. Nested elements never match adjacent sibling selectors.
mix-up
+ ≠ space ≠ >
Space = descendant. > = child. + = next sibling. Mixing them up is a common beginner error.
scope
Forms and wrappers
Many layouts wrap the input. Prefer label[for] / #id links, or .next() from a known label, when markup is not flat siblings.
Compatibility
Browser Support
The adjacent sibling combinator is standard CSS and has worked in jQuery since 1.0. Modern browsers implement it in native querySelectorAll.
✓ CSS · jQuery 1.0+
jQuery "prev + next"
Supported in all modern browsers. Native: document.querySelectorAll("label + input"). Universal CSS adjacent sibling combinator.
100%Standard CSS selector
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
Adjacent sibling (+)Universal
Bottom line: Safe everywhere jQuery runs. Use + for the immediate next sibling; use ~ when you need every following match.
Analysis
Performance Notes
Approach
Cost
Best for
$("prev + next")
Native CSS when possible
One-shot adjacent queries
$("prev").next("next")
Small traversal step
Starting from an existing set
$("prev ~ next")
Larger result set
All following siblings
Prefer the narrowest combinator that matches your intent. + is cheaper to reason about than ~ because it returns at most one sibling per previous match.
Remember
Key Takeaways
Role:prev + next selects the immediate next sibling only.
Parent rule: both sides must share the same parent.
Not ~: use general sibling when you need every following match.
Traversal: pair with .next() when you already hold elements.
One line:$("prev + next") means “the element right after prev” — nothing further, nothing nested.
Frequently Asked Questions
The adjacent sibling combinator prev + next selects elements matching next that are immediately preceded by a sibling matching prev. $("label + input") matches only inputs whose direct previous sibling is a label.
+ matches only the single element directly after prev. ~ matches every following sibling that matches next and shares the same parent. $("h2 + p") picks one lead paragraph; $("h2 ~ p") picks all following paragraphs.
A space matches nested descendants inside an ancestor. + matches siblings at the same level — both sides must share the same parent. $("div input") finds inputs inside div; $("label + input") finds inputs right after a label sibling.
Yes. Official jQuery docs note that for both + and ~, the elements on either side of the combinator must share the same parent.
$("prev + next") is a one-shot CSS selector from the document. .next("next") is a traversal method when you already hold a jQuery collection and want its immediate next sibling.
Since jQuery 1.0. It is standard CSS; modern browsers support it via document.querySelectorAll("label + input").