# Cypress Documentation
# Source: https://raw.githubusercontent.com/cypress-io/cypress-documentation/main/docs/api/commands/siblings.mdx
# Path: docs/api/commands/siblings.mdx

---
title: 'siblings | Cypress Documentation'
description: Get sibling DOM elements in Cypress.
sidebar_label: siblings
slug: /api/commands/siblings
---

<ProductHeading product="app" />

# siblings

Get sibling DOM elements.

## Syntax

```javascript
.siblings()
.siblings(selector)
.siblings(options)
.siblings(selector, options)
```

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

```javascript
cy.get('td').siblings() // Yield all td's siblings
cy.get('li').siblings('.active') // Yield all li's siblings with class '.active'
```

<Icon name="exclamation-triangle" color="red" /> **Incorrect Usage**

```javascript
cy.siblings('.error') // Errors, cannot be chained off 'cy'
cy.clock().siblings() // Errors, 'clock' does not yield DOM elements
```

### Arguments

<Icon name="angle-right" /> **selector _(String selector)_**

A selector used to filter matching DOM elements.

<Icon name="angle-right" /> **options _(Object)_**

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

| Option    | Default                                                           | Description                                                                         |
| --------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `log`     | `true`                                                            | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) |
| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `.siblings()` to resolve before [timing out](#Timeouts)            |

<HeaderYields />

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

## Examples

### No Args

#### Get the siblings of each `li`

```html
<ul>
  <li>Home</li>
  <li>Contact</li>
  <li class="active">Services</li>
  <li>Price</li>
</ul>
```

```javascript
// yields all other li's in list
cy.get('.active').siblings()
```

### Selector

#### Get siblings of element with class `active`

```javascript
// yields <li class="active">Services</li>
cy.get('li').siblings('.active')
```

## Rules

<HeaderRequirements />

- `.siblings()` requires being chained off a command that yields DOM element(s).

<HeaderAssertions />

- `.siblings()` will automatically [retry](/app/core-concepts/retry-ability)
  until the element(s)
  [exist in the DOM](/app/core-concepts/introduction-to-cypress#Implicit-Assertions).
- `.siblings()` will automatically [retry](/app/core-concepts/retry-ability)
  until all chained assertions have passed.

<HeaderTimeouts />

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

## Command Log

**_Get the siblings of element with class `active`_**

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

The commands above will display in the Command Log as:

<DocsImage
  src="/img/api/siblings/find-siblings-of-dom-elements-to-test.png"
  alt="Command Log siblings"
/>

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

<DocsImage
  src="/img/api/siblings/console-log-of-sibling-elements.png"
  alt="Console Log siblings"
/>

## History

| Version                                    | Changes                     |
| ------------------------------------------ | --------------------------- |
| [< 0.3.3](/app/references/changelog#0-3-3) | `.siblings()` command added |

## See also

- [`.prev()`](/api/commands/prev)
- [`.next()`](/api/commands/next)