jQuery Next Adjacent Selector (“prev + next”)

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Immediate next sibling

What You’ll Learn

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

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.

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.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( "prev + next" )

// common patterns:
$( "label + input" )
$( "h2 + p" )
$( "dt + dd" )
$( ".tab + .panel" )

Parameters

  • 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.

⚡ Quick Reference

Sibling relationshipprev + nextprev ~ next
Immediate next siblingMatchesMatches
Second or later following siblingNo matchMatches
Element between prev and nextNo matchNo match (for that pair)
Nested inside prev (descendant)No matchNo match
Different parentNo matchNo match

📋 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

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!”

jQuery
$( "label + input" ).css( "color", "blue" ).val( "Labeled!" );

// Matches inputs immediately after label siblings
// Name: [label][input]  Newsletter: [label][input]
Try It Yourself

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
Try It Yourself

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
Try It Yourself

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"
Try It Yourself

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
Try It Yourself

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.

🚀 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.

📝 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").

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
+ combinator Universal

Bottom line: Use + when you need the single element directly after prev. Prefer .next() when you already hold a jQuery collection.

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.

💡 Best Practices

✅ Do

  • 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

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
lbl 02

Official

label + input

Demo
~ 03

General

All following

Compare
gap 04

Immediate

No gap allowed

Pattern
.nx 05

.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.

Continue to General Sibling Selector

After adjacent sibling (+) matching, learn how to select all following siblings with the ~ combinator.

General sibling tutorial →

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.

6 people found this page helpful