jQuery .nextAll() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Traversing

Definition

.nextAll([selector]) (since jQuery 1.2) returns all following siblings of each matched element — every sibling that comes after it under the same parent. Optional selector filters that set. Returns a new jQuery object; does not change the DOM.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("li.third-item").nextAll();           // items 4 and 5
$("div").first().nextAll();             // all divs after the first
$(":nth-child(1)").nextAll("p");        // following p siblings only
$("li.third-item").nextAll().addBack(); // start + everything after

// next()     → only the immediate next sibling
// nextAll()  → all following siblings
// prevAll()  → all preceding siblings
// siblings() → all siblings (before + after)
CallWhat it does
Matched setStarting element(s)
selectorKeep only matching following siblings
DirectionForward only (after the start)
Return valueNew jQuery set (0 or more)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the starting element (e.g. $("li.third-item")).
Step 2Call .nextAll() for every following sibling.
Step 3Or pass a selector: .nextAll("p") to keep matching tags only.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — All List Items After the Third

Official idea: from li.third-item, mark every following li.

jQuery
$("li.third-item").nextAll().append(" [after]");
Try It Yourself

How It Works

  1. Start. Select the third item.
  2. Forward. Collect every sibling after it.
  3. Skip. Items 1–3 are not following siblings.

Example 2 — All Divs After the First

Official Ex. 1 idea: from the first div, take every later sibling div.

jQuery
$("div").first().nextAll().append(" [after]");
Try It Yourself

How It Works

  1. First. $("div").first() is the start.
  2. nextAll. Every later sibling under the same parent.
  3. Start out. The first div itself is not in the result.

Example 3 — Following Paragraphs Only

Official Ex. 2 idea: keep only following siblings that are p.

jQuery
$(":nth-child(1)").nextAll("p").append(" [p]");
Try It Yourself

How It Works

  1. Start. First child of the parent (often the first p).
  2. Walk. Consider every following sibling.
  3. Filter. Keep only those matching "p".

Frequently Asked Questions

.nextAll() returns a new jQuery object with all following siblings of each element in the current set — every sibling that comes after it under the same parent. An optional selector filters which of those siblings are kept.
.next() returns only the immediate next sibling (zero or one). .nextAll() returns every following sibling (zero or more). Use .next() for “the next one”; use .nextAll() for “everything after.”
.prevAll() collects preceding siblings (before the element). .siblings() collects all siblings both before and after — not including the element itself. .nextAll() only looks forward.
No. Only siblings that follow it. To include the start as well, chain .addBack() — for example $("li.third-item").nextAll().addBack().
.nextAll(selector) keeps only following siblings that match the selector — for example .nextAll("p") keeps following paragraph siblings and skips divs in between.
No. Like other jQuery traversing methods, it only queries the existing DOM and returns a new collection.

Next: .nextUntil() Method

Get following siblings until a matching stop element — a bounded forward walk.

.nextUntil() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

10 people found this page helpful