---
id: api/commands/parent
title: parent | Cypress Documentation
description: Get the parent DOM element of a set of DOM elements in Cypress.
section: api
source_path: docs/api/commands/parent.mdx
version: e6988a974973e9090ce70406c38cb2b9e0eac9fa
updated_at: '2026-05-15T15:50:22.536Z'
---
# parent

Get the parent DOM element of a set of DOM elements.

Please note that `.parent()` only travels a single level up the DOM tree as opposed to the [.parents()](/llm/markdown/api/commands/parents.md) command.

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

## Syntax

```
.parent().parent(selector).parent(options).parent(selector, options)
```

### Usage

**Correct Usage**

```
cy.get('header').parent() // Yield parent el of `header`
```

**Incorrect Usage**

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

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

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

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

## Examples

### No Args

#### Get the parent of the active `li`

```
<ul class="main-nav">  <li>Overview</li>  <li>    Getting started    <ul class="sub-nav">      <li>Install</li>      <li class="active">Build</li>      <li>Test</li>    </ul>  </li></ul>
```

```
// yields .sub-navcy.get('li.active').parent()
```

### Selector

#### Get the parent with class `sub-nav` of all `li` elements

```
<ul class="main-nav">  <li>Overview</li>  <li>    Getting started    <ul class="sub-nav">      <li>Install</li>      <li class="active">Build</li>      <li>Test</li>    </ul>  </li></ul>
```

```
// yields .sub-navcy.get('li').parent('.sub-nav')
```

## Rules

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

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

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

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

## Command Log

**_Assert on the parent of the active li_**

```
cy.get('li.active').parent().should('have.class', 'nav')
```

The commands above will display in the Command Log as:

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

## See also

*   [`.children()`](/llm/markdown/api/commands/children.md)
*   [`.parents()`](/llm/markdown/api/commands/parents.md)
*   [`.parentsUntil()`](/llm/markdown/api/commands/parentsuntil.md)
