---
id: api/commands/children
title: cy.children()
description: >-
  Get the direct children of each DOM element within a set of DOM elements in
  Cypress.
section: api
source_path: docs/api/commands/children.mdx
version: fc1f08bb3d8dafec7ab66b956c3d6168d5764c4f
updated_at: '2026-09-28T07:38:10.900Z'
---
# children

Get the children of each DOM element within a set of DOM elements.

`.children()` travels a single level down the DOM tree, as opposed to [`.find()`](/llm/markdown/api/commands/find.md), which searches every descendant.

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

## Syntax

```
.children()
.children(selector)
.children(options)
.children(selector, options)
```

### Usage

**Correct Usage**

```
cy.get('nav').children() // Yield children of nav
cy.get('nav').children('.active') // Yield children of nav with class '.active'
```

**Incorrect Usage**

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

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

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

### Yields

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

## Examples

### No Args

#### Get the children of the `.secondary-nav`

```
<ul>
  <li>About</li>
  <li>
    Services
    <ul class="secondary-nav">
      <li class="services-1">Web Design</li>
      <li class="services-2">Logo Design</li>
      <li class="services-3">
        Print Design
        <ul class="tertiary-nav">
          <li>Signage</li>
          <li>T-Shirt</li>
          <li>Business Cards</li>
        </ul>
      </li>
    </ul>
  </li>
  <li>Contact</li>
</ul>
```

```
// yields [
//  <li class="services-1">Web Design</li>,
//  <li class="services-2">Logo Design</li>,
//  <li class="services-3">Print Design<ul class="tertiary-nav">…</ul></li>
// ]
cy.get('ul.secondary-nav').children()
```

The three `<li>` elements inside `ul.tertiary-nav` are descendants of `ul.secondary-nav`, not children of it, so they are not part of the result. The `<li class="services-3">` that contains them is yielded whole, nested list and all.

### Selector

#### Get the children with class `active`

```
<div>
  <ul>
    <li class="active">Unit Testing</li>
    <li>Integration Testing</li>
  </ul>
</div>
```

```
// yields [
//  <li class="active">Unit Testing</li>
// ]
cy.get('ul').children('.active')
```

## Notes

### Shadow DOM boundaries and `.children()`

`.children()` stops at a shadow boundary. Called on a shadow host, it yields the children written inside that host in the page's markup, not the elements inside its shadow root. This holds whether or not [`includeShadowDom`](/llm/markdown/app/references/configuration.md#Global) is enabled, since that option applies to [`cy.get()`](/llm/markdown/api/commands/get.md#Arguments), [`.find()`](/llm/markdown/api/commands/find.md#Arguments), and [`cy.contains()`](/llm/markdown/api/commands/contains.md#Shadow-DOM). To query inside a shadow root, traverse into it with [`.shadow()`](/llm/markdown/api/commands/shadow.md) first.

## Rules

### Requirements

*   `.children()` requires being chained off a command that yields DOM element(s) or a document.

### Assertions

*   `.children()` 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).
*   `.children()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.

### Timeouts

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

## Command Log

**_Assert that there should be 8 children elements in a nav_**

```
cy.get('.left-nav>.nav').children().should('have.length', 8)
```

The commands above will display in the Command Log as:

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

## History

| Version | Changes |
| --- | --- |
| [12.0.0](/llm/markdown/app/references/changelog.md#12-0-0) | `.children()` is now a query. Overwrite it with [`Cypress.Commands.overwriteQuery()`](/llm/markdown/api/cypress-api/custom-queries.md#Overwriting-Existing-Queries) rather than `Cypress.Commands.overwrite()`. |

## See also

*   [`.find()`](/llm/markdown/api/commands/find.md)
*   [`.next()`](/llm/markdown/api/commands/next.md)
*   [`.parent()`](/llm/markdown/api/commands/parent.md)
*   [`.parents()`](/llm/markdown/api/commands/parents.md)
*   [`.siblings()`](/llm/markdown/api/commands/siblings.md)
