{
  "doc": {
    "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": "/llm/markdown/api/commands/children.md",
    "version": "f97f06d85653c51afe39a9bd3cefda946807f150",
    "updated_at": "2026-10-05T21:01:45.863Z",
    "headings": [
      {
        "id": "api/commands/children#children",
        "text": "children",
        "level": 1
      },
      {
        "id": "api/commands/children#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/children#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/children#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/children#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/children#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/children#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/children#get-the-children-of-the-secondary-nav",
        "text": "Get the children of the .secondary-nav",
        "level": 4
      },
      {
        "id": "api/commands/children#selector",
        "text": "Selector",
        "level": 3
      },
      {
        "id": "api/commands/children#get-the-children-with-class-active",
        "text": "Get the children with class active",
        "level": 4
      },
      {
        "id": "api/commands/children#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/children#shadow-dom-boundaries-and-children",
        "text": "Shadow DOM boundaries and .children()",
        "level": 3
      },
      {
        "id": "api/commands/children#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/children#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/children#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/children#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/children#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/children#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/children#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/children#syntax",
      "doc_id": "api/commands/children",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.children()\n.children(selector)\n.children(options)\n.children(selector, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('nav').children() // Yield children of nav\ncy.get('nav').children('.active') // Yield children of nav with class '.active'\n```\n\n**Incorrect Usage**\n\n```\ncy.children() // Errors, cannot be chained off 'cy'\ncy.clock().children() // Errors, 'clock' does not yield DOM elements\n```\n\n### Arguments\n\n**selector _(String selector)_**\n\nA selector used to filter matching DOM elements.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.children()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `.children()` to resolve before [timing out](#Timeouts) |\n\n### Yields\n\n*   `.children()` yields the new DOM element(s) it found.\n*   `.children()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 193
    },
    {
      "id": "api/commands/children#usage",
      "doc_id": "api/commands/children",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('nav').children() // Yield children of nav\ncy.get('nav').children('.active') // Yield children of nav with class '.active'\n```\n\n**Incorrect Usage**\n\n```\ncy.children() // Errors, cannot be chained off 'cy'\ncy.clock().children() // Errors, 'clock' does not yield DOM elements\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 56
    },
    {
      "id": "api/commands/children#arguments",
      "doc_id": "api/commands/children",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**selector _(String selector)_**\n\nA selector used to filter matching DOM elements.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.children()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `.children()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 93
    },
    {
      "id": "api/commands/children#examples",
      "doc_id": "api/commands/children",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Args\n\n#### Get the children of the `.secondary-nav`\n\n```\n<ul>\n  <li>About</li>\n  <li>\n    Services\n    <ul class=\"secondary-nav\">\n      <li class=\"services-1\">Web Design</li>\n      <li class=\"services-2\">Logo Design</li>\n      <li class=\"services-3\">\n        Print Design\n        <ul class=\"tertiary-nav\">\n          <li>Signage</li>\n          <li>T-Shirt</li>\n          <li>Business Cards</li>\n        </ul>\n      </li>\n    </ul>\n  </li>\n  <li>Contact</li>\n</ul>\n```\n\n```\n// yields [\n//  <li class=\"services-1\">Web Design</li>,\n//  <li class=\"services-2\">Logo Design</li>,\n//  <li class=\"services-3\">Print Design<ul class=\"tertiary-nav\">…</ul></li>\n// ]\ncy.get('ul.secondary-nav').children()\n```\n\nThe 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.\n\n### Selector\n\n#### Get the children with class `active`\n\n```\n<div>\n  <ul>\n    <li class=\"active\">Unit Testing</li>\n    <li>Integration Testing</li>\n  </ul>\n</div>\n```\n\n```\n// yields [\n//  <li class=\"active\">Unit Testing</li>\n// ]\ncy.get('ul').children('.active')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 173
    },
    {
      "id": "api/commands/children#no-args",
      "doc_id": "api/commands/children",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Get the children of the `.secondary-nav`\n\n```\n<ul>\n  <li>About</li>\n  <li>\n    Services\n    <ul class=\"secondary-nav\">\n      <li class=\"services-1\">Web Design</li>\n      <li class=\"services-2\">Logo Design</li>\n      <li class=\"services-3\">\n        Print Design\n        <ul class=\"tertiary-nav\">\n          <li>Signage</li>\n          <li>T-Shirt</li>\n          <li>Business Cards</li>\n        </ul>\n      </li>\n    </ul>\n  </li>\n  <li>Contact</li>\n</ul>\n```\n\n```\n// yields [\n//  <li class=\"services-1\">Web Design</li>,\n//  <li class=\"services-2\">Logo Design</li>,\n//  <li class=\"services-3\">Print Design<ul class=\"tertiary-nav\">…</ul></li>\n// ]\ncy.get('ul.secondary-nav').children()\n```\n\nThe 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.\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 128
    },
    {
      "id": "api/commands/children#get-the-children-of-the-secondary-nav",
      "doc_id": "api/commands/children",
      "heading": "Get the children of the .secondary-nav",
      "heading_level": 4,
      "content_markdown": "#### Get the children of the `.secondary-nav`\n\n```\n<ul>\n  <li>About</li>\n  <li>\n    Services\n    <ul class=\"secondary-nav\">\n      <li class=\"services-1\">Web Design</li>\n      <li class=\"services-2\">Logo Design</li>\n      <li class=\"services-3\">\n        Print Design\n        <ul class=\"tertiary-nav\">\n          <li>Signage</li>\n          <li>T-Shirt</li>\n          <li>Business Cards</li>\n        </ul>\n      </li>\n    </ul>\n  </li>\n  <li>Contact</li>\n</ul>\n```\n\n```\n// yields [\n//  <li class=\"services-1\">Web Design</li>,\n//  <li class=\"services-2\">Logo Design</li>,\n//  <li class=\"services-3\">Print Design<ul class=\"tertiary-nav\">…</ul></li>\n// ]\ncy.get('ul.secondary-nav').children()\n```\n\nThe 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.\n",
      "section": "api",
      "anchors": [
        "get-the-children-of-the-secondary-nav"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 124
    },
    {
      "id": "api/commands/children#selector",
      "doc_id": "api/commands/children",
      "heading": "Selector",
      "heading_level": 3,
      "content_markdown": "### Selector\n\n#### Get the children with class `active`\n\n```\n<div>\n  <ul>\n    <li class=\"active\">Unit Testing</li>\n    <li>Integration Testing</li>\n  </ul>\n</div>\n```\n\n```\n// yields [\n//  <li class=\"active\">Unit Testing</li>\n// ]\ncy.get('ul').children('.active')\n```\n",
      "section": "api",
      "anchors": [
        "selector"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 43
    },
    {
      "id": "api/commands/children#get-the-children-with-class-active",
      "doc_id": "api/commands/children",
      "heading": "Get the children with class active",
      "heading_level": 4,
      "content_markdown": "#### Get the children with class `active`\n\n```\n<div>\n  <ul>\n    <li class=\"active\">Unit Testing</li>\n    <li>Integration Testing</li>\n  </ul>\n</div>\n```\n\n```\n// yields [\n//  <li class=\"active\">Unit Testing</li>\n// ]\ncy.get('ul').children('.active')\n```\n",
      "section": "api",
      "anchors": [
        "get-the-children-with-class-active"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 40
    },
    {
      "id": "api/commands/children#notes",
      "doc_id": "api/commands/children",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Shadow DOM boundaries and `.children()`\n\n`.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.\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 89
    },
    {
      "id": "api/commands/children#shadow-dom-boundaries-and-children",
      "doc_id": "api/commands/children",
      "heading": "Shadow DOM boundaries and .children()",
      "heading_level": 3,
      "content_markdown": "### Shadow DOM boundaries and `.children()`\n\n`.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.\n",
      "section": "api",
      "anchors": [
        "shadow-dom-boundaries-and-children"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 87
    },
    {
      "id": "api/commands/children#rules",
      "doc_id": "api/commands/children",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `.children()` requires being chained off a command that yields DOM element(s) or a document.\n\n### Assertions\n\n*   `.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).\n*   `.children()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.\n\n### Timeouts\n\n*   `.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).\n*   `.children()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 96
    },
    {
      "id": "api/commands/children#command-log",
      "doc_id": "api/commands/children",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Assert that there should be 8 children elements in a nav_**\n\n```\ncy.get('.left-nav>.nav').children().should('have.length', 8)\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on the `children` command within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 57
    },
    {
      "id": "api/commands/children#history",
      "doc_id": "api/commands/children",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [12.6.0](/llm/markdown/app/references/changelog.md#12-6-0) | Overwrite `.children()` with [`Cypress.Commands.overwriteQuery()`](/llm/markdown/api/cypress-api/custom-queries.md#Overwriting-Existing-Queries) rather than `Cypress.Commands.overwrite()`. |\n| [12.0.0](/llm/markdown/app/references/changelog.md#12-0-0) | `.children()` is now a query. |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/children.json",
      "token_estimate": 43
    }
  ]
}