---
id: api/commands/parentsuntil
title: parentsUntil | Cypress Documentation
description: >-
  Get all ancestors of each DOM element in a set of matched DOM elements up to,
  but not including, the element provided in Cypress.
section: api
source_path: docs/api/commands/parentsuntil.mdx
version: 3cf5b86b3403f604bdf7f3e35025c3bc3865e02c
updated_at: '2026-05-07T17:44:31.931Z'
---
# parentsUntil

Get all ancestors of each DOM element in a set of matched DOM elements up to, but not including, the element provided.

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

## Syntax

```
.parentsUntil(selector).parentsUntil(selector, filter).parentsUntil(selector, filter, options).parentsUntil(element).parentsUntil(element, filter).parentsUntil(element, filter, options)
```

### Usage

**Correct Usage**

```
cy.get('p').parentsUntil('.article') // Yield parents of 'p' until '.article'
```

**Incorrect Usage**

```
cy.parentsUntil() // Errors, cannot be chained off 'cy'cy.clock().parentsUntil('href') // Errors, 'clock' does not yield DOM elements
```

### Arguments

**selector _(String selector)_**

The selector where you want finding parent ancestors to stop.

**element _(DOM node, jQuery Object)_**

The element where you want finding parent ancestors to stop.

**filter _(String selector)_**

A selector used to filter matching DOM elements.

**options _(Object)_**

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

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

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

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

## Examples

### Selector

#### Find all of the `.active` element's ancestors until `.nav`

```
<ul class="nav">  <li>    <a href="#">Clothes</a>    <ul class="menu">      <li>        <a href="/shirts">Shirts</a>      </li>      <li class="active">        <a href="/pants">Pants</a>      </li>    </ul>  </li></ul>
```

```
// yields [ul.menu, li]cy.get('.active').parentsUntil('.nav')
```

## Rules

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

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

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

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

## Command Log

**_Find all of the `active` element's ancestors until `.nav`_**

```
cy.get('.active').parentsUntil('.nav')
```

The commands above will display in the Command Log as:

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

## See also

*   [`.parent()`](/llm/markdown/api/commands/parent.md)
*   [`.parents()`](/llm/markdown/api/commands/parents.md)
*   [`.prevUntil()`](/llm/markdown/api/commands/prevuntil.md)
*   [`.nextUntil()`](/llm/markdown/api/commands/nextuntil.md)
