---
id: api/commands/prev
title: prev | Cypress Documentation
description: >-
  Get the immediately preceding sibling of each element in a set of the elements
  in Cypress.
section: api
source_path: docs/api/commands/prev.mdx
version: 7ada28c0cd90e81cf56fd3fc73de6e6d45c16de6
updated_at: '2026-05-13T21:55:41.935Z'
---
# prev

Get the immediately preceding sibling of each element in a set of the elements.

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

## Syntax

```
.prev().prev(selector).prev(options).prev(selector, options)
```

### Usage

**Correct Usage**

```
cy.get('tr.highlight').prev() // Yield previous 'tr'
```

**Incorrect Usage**

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

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

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

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

## Examples

### No Args

#### Find the previous element of the element with class of `active`

```
<ul>  <li>Cockatiels</li>  <li>Lorikeets</li>  <li class="active">Cockatoos</li>  <li>Conures</li>  <li>Eclectus</li></ul>
```

```
// yields <li>Lorikeets</li>cy.get('.active').prev()
```

### Selector

#### Find the previous element with a class of `active`

```
<ul>  <li>Cockatiels</li>  <li>Lorikeets</li>  <li class="active">Cockatoos</li>  <li>Conures</li>  <li>Eclectus</li></ul>
```

```
// yields <li>Cockatoos</li>cy.get('li').prev('.active')
```

## Rules

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

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

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

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

## Command Log

**_Find the previous element of the active `li`_**

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

The commands above will display in the Command Log as:

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

## See also

*   [`.next()`](/llm/markdown/api/commands/next.md)
*   [`.prevAll()`](/llm/markdown/api/commands/prevall.md)
*   [`.prevUntil()`](/llm/markdown/api/commands/prevuntil.md)
