The next adjacent selector uses the + combinator to match elements that are the immediate next sibling of a preceding element — not all following siblings. Available since jQuery 1.0; ideal for label+input pairs, heading+paragraph styling, and definition lists.
01
Syntax
prev + next
02
Adjacent
One sibling only
03
Official
label + input
04
vs ~
General sibling
05
Same parent
Shared parent required
06
CSS
Standard combinator
Fundamentals
Introduction
Siblings share the same parent. When you need to style or manipulate an element based on what comes directly before it — not nested inside it, and not several siblings later — the adjacent sibling combinator + is the right tool.
Official jQuery documentation describes prev + next as selecting elements matching next that are immediately preceded by sibling prev. Both sides must share the same parent. This is stricter than the general sibling combinator ~, which matches all following siblings. This tutorial walks through the official label + input demo and practical patterns for forms, typography, and definition lists.
Concept
Understanding the Next Adjacent Selector
Think of prev + next as a one-step sibling relationship: “Is this element the very next sibling after that element?”
label + input → inputs whose immediate previous sibling is a label.
h2 + p → the paragraph directly after each h2 — not later paragraphs.
dt + dd → definition descriptions that immediately follow their term.
💡
Beginner Tip
If another element sits between prev and next, the match fails. A blank text node does not break the chain, but an element like <span> or <br> does. Use ~ when you need all following siblings, not just the next one.
prev — any valid selector for the preceding sibling element(s).
next — a selector for the element that must immediately follow each matched prev.
Return value
A jQuery object containing every element that is the immediate next sibling of a matched prev.
At most one next element per matching prev — not all following siblings.
Official jQuery API example
jQuery
// Labels its following input with the text "Labeled!"
$( "label + input" ).css( "color", "blue" ).val( "Labeled!" );
Official markup pattern: Name: label+input, Newsletter: label+input — each input directly follows its label sibling.
Cheat Sheet
⚡ Quick Reference
Sibling relationship
prev + next
prev ~ next
Immediate next sibling
Matches
Matches
Second or later following sibling
No match
Matches
Element between prev and next
No match
No match (for that pair)
Nested inside prev (descendant)
No match
No match
Different parent
No match
No match
Compare
📋 Adjacent (+) vs Related Combinators
Same DOM tree — different relationship rules.
Adjacent
label + input
Immediate next sibling only
General sibling
h2 ~ p
All following siblings
Child
form > input
Direct child of parent
Descendant
form input
Nested at any depth
.next()
$("label").next("input")
Traversal equivalent
Hands-On
Examples Gallery
Example 1 follows the official jQuery label + input demo. Examples 2–5 style heading paragraphs, compare sibling vs nested selectors, show why a gap breaks the match, and target definition list pairs. Use the Try-it links to run each snippet.
📚 Official jQuery Demo
Label inputs that directly follow label siblings — official API markup pattern.
Example 1 — Official Demo: label + input
Official jQuery demo — color inputs blue and set their value to “Labeled!”
Name input → blue text, value "Labeled!"
Newsletter input → blue text, value "Labeled!"
Other inputs not directly after a label → unchanged
How It Works
Each matched input must have a label as its immediate previous sibling. Inputs inside wrappers or separated by other elements are skipped — only the direct label+input pairs match.
Example 2 — Style Paragraph After Heading: h2 + p
Apply lead-paragraph styling to the paragraph directly following each h2.
jQuery
$( "h2 + p" ).css( "font-size", "1.1em" ).css( "color", "#444" );
// Only the first paragraph after each h2 — not later paragraphs
First p after each h2 → larger, darker text
Second and third paragraphs → default styling
How It Works
h2 + p picks at most one paragraph per heading — the lead paragraph. Later paragraphs under the same section are not adjacent to the h2, so they stay untouched.
📈 Practical Patterns
Sibling vs nested relationships, gaps, and semantic markup pairs.
Example 3 — Sibling vs Descendant: label + input vs div input
Compare adjacent sibling matching with descendant (nested) matching.
jQuery
console.log( "Adjacent siblings:", $( "label + input" ).length );
console.log( "Nested in div:", $( "div input" ).length );
// label + input = same-level siblings only
// div input = any input inside a div at any depth
Adjacent siblings: 2 (label directly before input)
Nested in div: 4 (includes inputs inside nested wrappers)
How It Works
+ requires the same parent and immediate adjacency. A space finds nested descendants regardless of sibling order — useful when markup wraps inputs inside divs.
Example 4 — Gap Breaks the Match: + Only Immediate Next
Show that an element between siblings prevents a + match.
jQuery
$( "label + input" ).addClass( "adjacent" );
// label → span → input: input is NOT adjacent to label
// label → input: input IS adjacent — gets class "adjacent"
Direct label+input pair → class "adjacent"
label → span → input → no class (span breaks adjacency)
How It Works
The combinator checks the single element immediately before next. If that element is not a matching prev, the selector fails — even if a matching prev exists earlier among siblings.
Example 5 — Definition Lists: dt + dd
Style definition descriptions that immediately follow their term.
jQuery
$( "dt + dd" ).css( "margin-left", "1em" ).css( "color", "#555" );
// Each dd must directly follow its dt sibling
Term 1 → dd styled (indented, gray)
Term 2 → dd styled
Misplaced dd not after dt → unchanged
How It Works
Semantic <dl> markup pairs dt terms with dd descriptions. The adjacent combinator enforces the expected dt-then-dd order without selecting unrelated dd elements.
Applications
🚀 Common Use Cases
Form labels — style or populate inputs immediately after label siblings.
Typography — style the lead paragraph after each heading with h2 + p.
Tab interfaces — show the panel directly after an active tab button.
Definition lists — indent and color dd elements following dt terms.
Error messages — highlight validation text placed immediately after invalid fields.
Icon + text pairs — style captions or labels that directly follow icon elements.
🧠 How jQuery Evaluates prev + next
1
Find prev matches
jQuery first matches every element that satisfies the prev part of the selector.
Prev
2
Check next sibling
For each matched prev, look at its immediate next sibling element only.
Adjacent
3
Filter by next
Keep the sibling only if it matches the next selector and shares the same parent.
Filter
4
✓
Return collection
Matched adjacent siblings become a jQuery object for chaining.
Important
📝 Notes
Available since jQuery 1.0 — standard CSS adjacent sibling combinator syntax.
Both prev and next must share the same parent element.
Only the direct next sibling matches — not second, third, or later following siblings.
For all following siblings, use the general sibling combinator ~ instead.
Whitespace around + is optional: label+input and label + input both work.
Equivalent traversal: $("prev").next("next").
Compatibility
Browser Support
The + adjacent sibling combinator is standard CSS and works in jQuery 1.0+. Modern browsers support document.querySelectorAll("label + input") natively. jQuery provides consistent cross-browser behavior for sibling selection.
✓ CSS · jQuery 1.0+
jQuery Next Adjacent Selector ("+")
Supported in all modern browsers. Native: document.querySelectorAll("prev + next"). Immediate next sibling only — not all following siblings.
100%Standard CSS
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
+ combinatorUniversal
Bottom line: Use + when you need the single element directly after prev. Prefer .next() when you already hold a jQuery collection.
Wrap Up
Conclusion
The next adjacent selector prev + next matches elements that are the immediate next sibling of a preceding match — a precise tool for label+input pairs, heading lead paragraphs, and definition lists. The official label + input demo shows the pattern: only inputs directly after labels are styled and updated.
When you need all following siblings — not just the next one — switch to ~. For parent-child or nested relationships, use > or a space. Traversal methods like .next() offer the same adjacent logic from an existing jQuery object.
Use + for label+input and other direct sibling pairs
Compare + vs ~ when multiple siblings follow
Verify markup has no elements between prev and next
Use .next() when starting from a jQuery object
Scope with a parent class or ID when possible
❌ Don’t
Assume + and ~ behave the same
Use + when you need nested (descendant) matches
Expect a match when another element sits between siblings
Forget that both elements must share the same parent
Skip testing with realistic markup gaps in Try-it examples
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about the adjacent selector
Immediate next sibling only — at most one match per prev.
5
Core concepts
+01
Adjacent
Next sibling
Rule
lbl02
Official
label + input
Demo
~03
General
All following
Compare
gap04
Immediate
No gap allowed
Pattern
.nx05
.next()
Traversal twin
API
❓ 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 — not inputs separated by other elements.
+ matches only the single element directly after prev. ~ matches every following sibling that satisfies next, as long as they share the same parent. $("h2 + p") picks one paragraph per h2; $("h2 ~ p") picks all paragraphs after each h2 until a new h2 breaks the group.
A space matches nested descendants at any depth inside an ancestor. + matches siblings at the same level — both elements must share the same parent. $("div input") finds inputs inside div; $("label + input") finds inputs immediately after a label sibling.
Official docs use $("label + input").css("color", "blue").val("Labeled!") on markup with Name: label+input and Newsletter: label+input — styling and setting the value of inputs that directly follow label siblings.
Both target the immediate next sibling. $("prev + next") is a CSS selector — great for one-shot queries from the document root. .next("next") is a jQuery traversal method — useful when you already hold a jQuery object and want to filter the very next sibling.
Yes. The + combinator is standard CSS and works in jQuery 1.0+. Native document.querySelectorAll("label + input") uses the same syntax in modern browsers.
Did you know?
The + combinator picks at most one next sibling per matching prev — if three paragraphs follow an h2, only the first can match h2 + p. The general sibling combinator ~ would match all three.