jQuery .nextAll() Method

Beginner
5 min read
Updated: Oct 2026
5 examples
Live preview

What Is .nextAll()?

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

Remember
$("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)
NeedUse
All following siblings$el.nextAll()
Immediate next sibling.next()
Until a stop element.nextUntil()
All preceding siblings.prevAll()
All siblings.siblings()

How to Use .nextAll()

Select a starting sibling, then collect everything after it.

  1. Select the starting element (e.g. $("li.third-item")).
  2. Call .nextAll() for every following sibling.
  3. Or pass a selector: .nextAll("p") to keep matching tags only.
  4. Chain methods on the new set (.append(), .each(), …).
  5. Need the start too? Chain .addBack().
PieceRequired?Role
Matched setYesStarting element(s)
selectorNoKeep only matching following siblings
Direction—Forward only (after the start)
Return value—New jQuery set (0 or more)

Pseudocode

Pseudocode
call $(starts).nextAll(selector?)

result = empty set
for each start in the matched set:
    sibling = start.nextElementSibling
    while sibling is not null:
        if no selector OR sibling matches selector:
            add sibling to result
        sibling = sibling.nextElementSibling

return result as a new jQuery object
(start itself is never included)

Cheat Sheet

Keep these sibling methods side by side.

TopicDetail
Syntax.nextAll([selector])
SincejQuery 1.2
Includes start?No (use .addBack())
vs .next()One sibling vs all following
vs .nextUntil()All following vs until a stop
vs .prevAll()Forward vs backward
DOM change?No — query only

Live Preview

From li.third-item, compare .next(), .nextAll(), and .addBack().

  • list item 1
  • list item 2
  • list item 3
  • list item 4
  • list item 5

nextAll → items 4–5. next → item 4 only. addBack → items 3–5.

Result
Ready — choose a call and click Run.

jQuery Examples

Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.

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.
  4. Mark. Only 4 and 5 get the suffix.

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.
  4. Mark. The three following divs are tagged.

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".
  4. Divs. Non-p siblings are not included.

Example 4 — .next() vs .nextAll()

Same start — one sibling versus all following siblings.

jQuery
$("#next-demo li.third-item").next().append(" [next]");
$("#nextall-demo li.third-item").nextAll().append(" [nextAll]");
Try It Yourself

How It Works

  1. next. Stops after the immediate neighbor.
  2. nextAll. Keeps walking until no sibling remains.
  3. Same start. Both begin at item 3.
  4. Pick. Use next for one step; nextAll for the rest of the row.

Example 5 — Include the Start with .addBack()

Mark the starting item plus every following sibling.

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

How It Works

  1. nextAll. Gets items 4 and 5.
  2. addBack. Re-adds the previous set (item 3).
  3. Result. Items 3–5 in one collection.
  4. Use. “This item and everything after it.”

Edge Cases & Pitfalls

Why a following-sibling set can look “too short.”

start

Start element is never included

Chain .addBack() when you need “this one and the rest.”

parent

Only same-parent siblings

Children of another container are not siblings — .nextAll() will not reach them.

filter

Selector skips non-matches

.nextAll("p") walks past divs without including them — that is intentional filtering.

last

Last sibling → empty set

Nothing follows the last child. Check .length when that matters.

until

Need a stop point?

Use .nextUntil() instead of filtering after a full .nextAll().

Browser Support

.nextAll() has been part of jQuery since 1.2. It works in every browser that runs your loaded jQuery version — no separate browser feature flag.

✓ Stable · jQuery 1.2+

jQuery .nextAll()

Supported across jQuery 1.x, 2.x, and 3.x. Prefer a current jQuery 3.x build. Sibling walks use the live DOM tree.

100% With jQuery
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
.nextAll() Universal

Bottom line: Safe for lists, steppers, and “everything after this row” UI. Pair with .addBack() when the start must stay selected.

Performance Notes

ApproachCostBest for
.next()CheapestOne step forward
.nextAll()Linear in siblings afterRest of the sibling list
.nextUntil(stop)Stops earlyBounded forward range

Prefer .next() when you only need the neighbor, and .nextUntil() when you have a clear end marker.

Key Takeaways

  • Role: all following siblings — since jQuery 1.2.
  • Filter: optional selector keeps matching siblings only.
  • vs next: one neighbor vs the whole forward list.
  • Include start: chain .addBack().

One line: .nextAll() grabs every sibling after the current element — not the element itself.

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

10 people found this page helpful