---
id: api/commands/last
title: last | Cypress Documentation
description: Get the last DOM element within a set of DOM elements in Cypress.
section: api
source_path: docs/api/commands/last.mdx
version: ce02913654e2655ee63448bdc92bb92c7b46a619
updated_at: '2026-04-22T19:37:51.587Z'
---
# last

Get the last DOM element within a set of DOM elements.

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

## Syntax

```javascript
.last()
.last(options)
```

### Usage

 **Correct Usage**

```javascript
cy.get('nav a').last() // Yield last link in nav
```

 **Incorrect Usage**

```javascript
cy.last() // Errors, cannot be chained off 'cy'
cy.getCookies().last() // Errors, 'getCookies' does not yield DOM element
```

### Arguments

 **options *(Object)***

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

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

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

- `.last()` yields the new DOM element it found.
- `.last()` is a query, and it is *safe* to chain further commands.

## Examples

### No Args

#### Get the last list item in a list

```html
<ul>
  <li class="one">Knick knack on my thumb</li>
  <li class="two">Knick knack on my shoe</li>
  <li class="three">Knick knack on my knee</li>
  <li class="four">Knick knack on my door</li>
</ul>
```

```javascript
// yields <li class="four">Knick knack on my door</li>
cy.get('li').last()
```

## Rules

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

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

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

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

## Command Log

***Find the last button in the form***

```javascript
cy.get('form').find('button').last()
```

The commands above will display in the Command Log as:

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

## See also

- [`.eq()`](/llm/markdown/api/commands/eq.md)
- [`.first()`](/llm/markdown/api/commands/first.md)
