---
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: 3cf5b86b3403f604bdf7f3e35025c3bc3865e02c
updated_at: '2026-05-07T17:44:31.931Z'
---
# 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

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

### Usage

**Correct Usage**

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

**Incorrect Usage**

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

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

```
// 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_**

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