---
id: api/commands/prevuntil
title: prevUntil | Cypress Documentation
description: >-
  Get all previous siblings of each DOM element in a set of matched DOM elements
  up to, but not including, the element provided in Cypress.
section: api
source_path: docs/api/commands/prevuntil.mdx
version: 48b03b5502f7aea1d0454750cce208f775403542
updated_at: '2026-05-20T19:00:20.270Z'
---
# prevUntil

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

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

## Syntax

```
.prevUntil(selector).prevUntil(selector, filter).prevUntil(selector, filter, options).prevUntil(element).prevUntil(element, filter).prevUntil(element, filter, options)
```

### Usage

**Correct Usage**

```
cy.get('p').prevUntil('.intro') // Yield siblings before 'p' until '.intro'
```

**Incorrect Usage**

```
cy.prevUntil() // Errors, cannot be chained off 'cy'cy.location().prevUntil('path') // Errors, 'location' does not yield DOM element
```

### Arguments

**selector _(String selector)_**

The selector where you want finding previous siblings to stop.

**element _(DOM node, jQuery Object)_**

The element where you want finding previous siblings to stop.

**filter _(String selector)_**

A selector used to filter matching DOM elements.

**options _(Object)_**

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

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

### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)

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

## Examples

### Selector

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

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

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

## Rules

### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)

*   `.prevUntil()` 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)

*   `.prevUntil()` 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).
*   `.prevUntil()` 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)

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

## Command Log

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

```
cy.get('#nuts').prevUntil('#veggies')
```

The commands above will display in the Command Log as:

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

## See also

*   [`.prev()`](/llm/markdown/api/commands/prev.md)
*   [`.prevAll()`](/llm/markdown/api/commands/prevall.md)
*   [`.parentsUntil()`](/llm/markdown/api/commands/parentsuntil.md)
*   [`.nextUntil()`](/llm/markdown/api/commands/nextuntil.md)
