---
id: api/commands/next
title: next | Cypress Documentation
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: 48b03b5502f7aea1d0454750cce208f775403542
updated_at: '2026-05-20T19:00:20.270Z'
---
# 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 [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)

*   `.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 [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)

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

### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#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 [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#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)
