---
id: api/commands/prevall
title: cy.prevAll()
description: >-
  Get all previous siblings of each DOM element in a set of matched DOM elements
  in Cypress.
section: api
source_path: docs/api/commands/prevall.mdx
version: 834fef0fab3aeb0e29bf3a7c6a6d9b8b878ec8fb
updated_at: '2026-08-24T17:26:07.874Z'
---
# prevAll

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

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

## Syntax

```
.prevAll()
.prevAll(selector)
.prevAll(options)
.prevAll(selector, options)
```

### Usage

**Correct Usage**

```
cy.get('.active').prevAll() // Yield all links previous to `.active`
```

**Incorrect Usage**

```
cy.prevAll() // Errors, cannot be chained off 'cy'
cy.getCookies().prevAll() // 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 `.prevAll()`.

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

### Yields

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

## Examples

### No Args

#### Find all of the element's siblings before `.third`

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

```
// yields [<li>apples</li>, <li>oranges</li>]
cy.get('.third').prevAll()
```

### Selector

#### Find all of the previous siblings 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>
  <li>grapes</li>
</ul>
```

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

## Rules

### Requirements

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

### Assertions

*   `.prevAll()` 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).
*   `.prevAll()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.

### Timeouts

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

## Command Log

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

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

The commands above will display in the Command Log as:

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

## See also

*   [`.nextAll()`](/llm/markdown/api/commands/nextall.md)
*   [`.parents()`](/llm/markdown/api/commands/parents.md)
*   [`.prev()`](/llm/markdown/api/commands/prev.md)
*   [`.prevUntil()`](/llm/markdown/api/commands/prevuntil.md)
