.next([selector]) (since jQuery 1.0) returns the immediately following sibling of each element in the set. With an optional selector, that sibling is kept only if it matches.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$("li.third-item").next(); // item 4
$("button[disabled]").next(); // next sibling after each disabled button
$("p").next(".selected"); // next sibling only if it has .selected
// Not the same:
$("li").nextAll(); // all following siblings
Call
What it does
Current set
Elements whose next sibling you want
selector
Keep the next sibling only if it matches
Return value
New jQuery object (0 or more next siblings)
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Select the starting element(s).
Step 2
Call .next() for the immediate following sibling.
Step 3
Optionally pass a selector to keep that sibling only if it matches.
Return Value
Return Value
Description
Boolean
Often true or false depending on the match or state.
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
Example 1 — Official List Demo
From the jQuery docs: red background on the item right after li.third-item.
Only next siblings that have .selected → yellow
Non-matching next siblings → dropped
How It Works
Start. Every p is a starting point.
next. Look at each paragraph’s immediate sibling.
Filter. Keep it only if it matches .selected.
Frequently Asked Questions
.next() returns the immediately following sibling of each element in the current set. It moves sideways in the DOM — not into children and not up to parents. Without a selector, the very next element sibling is included if one exists. Available since jQuery 1.0.
.next() returns at most one sibling — the direct next neighbor. .nextAll() returns every following sibling. From list item 3, .next() gives item 4 only; .nextAll() gives items 4 and 5.
.next() looks forward to the following sibling; .prev() looks backward to the preceding sibling. Same distance (one step), opposite direction.
jQuery returns an empty collection (length 0). Chaining stays safe: .next().addClass("x") does nothing when no neighbor exists. Check .next().length when you need a boolean.
No. .next(selector) tests only the immediately following sibling. If that sibling does not match, the result is empty — jQuery does not keep scanning. Use .nextAll(selector).first() when you need the next match further along.
Yes. jQuery runs .next() for each element in the set and combines the results. $("p").next() returns the next sibling of every paragraph.