# Cypress Documentation
# Source: https://raw.githubusercontent.com/cypress-io/cypress-documentation/main/docs/api/commands/nextall.mdx
# Path: docs/api/commands/nextall.mdx

---
title: 'nextAll | Cypress Documentation'
description: Get all following siblings of each DOM element in a set of matched DOM elements in Cypress.
sidebar_label: nextAll
slug: /api/commands/nextall
---

<ProductHeading product="app" />

# nextAll

Get all following siblings of each DOM element in a set of matched DOM elements.

:::info

The querying behavior of this command matches exactly how
[`.nextAll()`](http://api.jquery.com/nextAll) works in jQuery.

:::

## Syntax

```javascript
.nextAll()
.nextAll(selector)
.nextAll(options)
.nextAll(selector, options)
```

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

```javascript
cy.get('.active').nextAll() // Yield all links next to `.active`
```

<Icon name="exclamation-triangle" color="red" /> **Incorrect Usage**

```javascript
cy.nextAll() // Errors, cannot be chained off 'cy'
cy.getCookies().nextAll() // Errors, 'getCookies' does not yield DOM element
```

### Arguments

<Icon name="angle-right" /> **selector _(String selector)_**

A selector used to filter matching DOM elements.

<Icon name="angle-right" /> **options _(Object)_**

Pass in an options object to change the default behavior of `.nextAll()`.

| Option    | Default                                                           | Description                                                                         |
| --------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `log`     | `true`                                                            | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) |
| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `.nextAll()` to resolve before [timing out](#Timeouts)             |

<HeaderYields />

- `.nextAll()` yields the new DOM element(s) it found.
- `.nextAll()` is a query, and it is _safe_ to chain further commands.

## Examples

### No Args

#### Find all of the element's siblings following `.second`

```html
<ul>
  <li>apples</li>
  <li class="second">oranges</li>
  <li>bananas</li>
  <li>pineapples</li>
  <li>grapes</li>
</ul>
```

```javascript
// yields [<li>bananas</li>, <li>pineapples</li>, <li>grapes</li>]
cy.get('.second').nextAll()
```

### Selector

#### Find all of the following siblings of each li. Keep only the ones with a class `selected`

```html
<ul>
  <li>apples</li>
  <li>oranges</li>
  <li>bananas</li>
  <li class="selected">pineapples</li>
  <li>grapes</li>
</ul>
```

```javascript
// yields <li>pineapples</li>
cy.get('li').nextAll('.selected')
```

## Rules

<HeaderRequirements />

- `.nextAll()` requires being chained off a command that yields DOM element(s).

<HeaderAssertions />

- `.nextAll()` will automatically [retry](/app/core-concepts/retry-ability)
  until the element(s)
  [exist in the DOM](/app/core-concepts/introduction-to-cypress#Implicit-Assertions).
- `.nextAll()` will automatically [retry](/app/core-concepts/retry-ability)
  until all chained assertions have passed.

<HeaderTimeouts />

- `.nextAll()` can time out waiting for the element(s) to
  [exist in the DOM](/app/core-concepts/introduction-to-cypress#Implicit-Assertions).
- `.nextAll()` can time out waiting for assertions you've added to pass.

## Command Log

**_Find all elements following the `.active` li_**

```javascript
cy.get('.left-nav').find('li.active').nextAll()
```

The commands above will display in the Command Log as:

<DocsImage
  src="/img/api/nextall/next-all-traversal-command-for-the-dom.png"
  alt="Command Log nextAll"
/>

When clicking on `nextAll` within the command log, the console outputs the
following:

<DocsImage
  src="/img/api/nextall/all-next-elements-are-logged-in-console.png"
  alt="Console Log nextAll"
/>

## See also

- [`.next()`](/api/commands/next)
- [`.nextUntil()`](/api/commands/nextuntil)
- [`.prevAll()`](/api/commands/prevall)