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

---
title: 'nextUntil | Cypress Documentation'
description: Get all following siblings of each DOM element in a set of matched DOM elements up to, but not including, the element provided in Cypress.
sidebar_label: nextUntil
slug: /api/commands/nextuntil
---

<ProductHeading product="app" />

# nextUntil

Get all following siblings of each DOM element in a set of matched DOM elements
up to, but not including, the element provided.

:::info

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

:::

## Syntax

```javascript
.nextUntil(selector)
.nextUntil(selector, filter)
.nextUntil(selector, filter, options)
.nextUntil(element)
.nextUntil(element, filter)
.nextUntil(element, filter, options)
```

### Usage

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

```javascript
cy.get('div').nextUntil('.warning') // Yield siblings after 'div' until '.warning'
```

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

```javascript
cy.nextUntil() // Errors, cannot be chained off 'cy'
cy.clock().nextUntil('path') // Errors, 'clock' does not yield DOM elements
```

### Arguments

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

The selector where you want finding next siblings to stop.

<Icon name="angle-right" /> **element _(DOM node, jQuery Object)_**

The element where you want finding next siblings to stop.

<Icon name="angle-right" /> **filter _(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 `.nextUntil()`.

| 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 `.nextUntil()` to resolve before [timing out](#Timeouts)           |

<HeaderYields />

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

## Examples

### Selector

#### Find all of the element's siblings following `#veggies` until `#nuts`

```html
<ul>
  <li id="fruits" class="header">Fruits</li>
  <li>apples</li>
  <li>oranges</li>
  <li>bananas</li>
  <li id="veggies" class="header">Vegetables</li>
  <li>cucumbers</li>
  <li>carrots</li>
  <li>corn</li>
  <li id="nuts" class="header">Nuts</li>
  <li>walnuts</li>
  <li>cashews</li>
  <li>almonds</li>
</ul>
```

```javascript
//returns [<li>cucumbers</li>, <li>carrots</li>, <li>corn</li>]
cy.get('#veggies').nextUntil('#nuts')
```

## Rules

<HeaderRequirements />

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

<HeaderAssertions />

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

<HeaderTimeouts />

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

## Command Log

**_Find all of the element's siblings following `#veggies` until `#nuts`_**

```javascript
cy.get('#veggies').nextUntil('#nuts')
```

The commands above will display in the Command Log as:

<DocsImage
  src="/img/api/nextuntil/find-next-elements-until-selector.png"
  alt="Command Log nextUntil"
/>

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

<DocsImage
  src="/img/api/nextuntil/console-log-of-next-elements-until.png"
  alt="Console Log nextUntil"
/>

## See also

- [`.next()`](/api/commands/next)
- [`.nextAll()`](/api/commands/nextall)
- [`.parentsUntil()`](/api/commands/parentsuntil)
- [`.prevUntil()`](/api/commands/prevuntil)