---
id: api/commands/next
title: cy.next()
description: >-
  Get the immediately following sibling of each DOM element within a set of DOM
  elements in Cypress.
section: api
source_path: docs/api/commands/next.mdx
version: 3163d68b20e695f2c76d40c85c3f3b956dd19a3b
updated_at: '2026-08-21T20:59:04.402Z'
---
# next

Get the immediately following sibling of each DOM element within a set of DOM elements.

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

## Syntax

```
.next()
.next(selector)
.next(options)
.next(selector, options)
```

### Usage

**Correct Usage**

```
cy.get('nav a:first').next() // Yield next link in nav
```

**Incorrect Usage**

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

### Arguments

**selector _(String selector)_**

A selector used to filter matching DOM elements.

**options _(Object)_**

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

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

### Yields

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

## Examples

### No Args

#### Find the element next to `.second`

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

```
// yields <li>bananas</li>
cy.get('.second').next()
```

#### Testing a datalist

```
<input list="fruit" />
<datalist id="fruit">
  <option>Apple</option>
  <option>Banana</option>
  <option>Cantaloupe</option>
</datalist>
```

```
cy.get('#fruit option')
  .first()
  .should('have.text', 'Apple')
  .next()
  .should('have.text', 'Banana')
  .next()
  .should('have.text', 'Cantaloupe')
```

### Selector

#### Find the very next sibling of each li. Keep only the ones with a class `selected`

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

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

## Rules

### Requirements

*   `.next()` requires being chained off a command that yields DOM element(s).

### Assertions

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

### Timeouts

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

## Command Log

**_Find the element next to the `.active` li_**

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

The commands above will display in the Command Log as:

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

## See also

*   [`.nextAll()`](/llm/markdown/api/commands/nextall.md)
*   [`.nextUntil()`](/llm/markdown/api/commands/nextuntil.md)
*   [`.prev()`](/llm/markdown/api/commands/prev.md)
