{
  "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": "f60251bf707b0077a9535579c9f90d615440cc35",
    "updated_at": "2026-10-16T10:56:58.670Z",
    "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
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "children"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Get the children of each DOM element within a set of DOM elements."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`.children()` travels a single level down the DOM tree, as opposed to "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/find.md",
            "children": [
              {
                "type": "text",
                "value": "`.find()`"
              }
            ]
          },
          {
            "type": "text",
            "value": ", which searches every descendant."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The querying behavior of this command matches exactly how "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://api.jquery.com/children",
            "children": [
              {
                "type": "text",
                "value": "`.children()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " works in jQuery."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": ".children()\n.children(selector)\n.children(options)\n.children(selector, options)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('nav').children() // Yield children of nav\ncy.get('nav').children('.active') // Yield children of nav with class '.active'"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Incorrect Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.children() // Errors, cannot be chained off 'cy'\ncy.clock().children() // Errors, 'clock' does not yield DOM elements"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "selector (String selector)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "A selector used to filter matching DOM elements."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "options (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass in an options object to change the default behavior of `.children()`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Default"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`log`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Displays the command in the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/open-mode.md#Command-Log",
                    "children": [
                      {
                        "type": "text",
                        "value": "Command log"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`timeout`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "`defaultCommandTimeout`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Time to wait for `.children()` to resolve before "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "timing out"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Yields"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.children()` yields the new DOM element(s) it found."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.children()` is a query, and it is safe to chain further commands."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "No Args"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Get the children of the `.secondary-nav`"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<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>"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// 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()"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "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."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Selector"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Get the children with class `active`"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<div>\n  <ul>\n    <li class=\"active\">Unit Testing</li>\n    <li>Integration Testing</li>\n  </ul>\n</div>"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// yields [\n//  <li class=\"active\">Unit Testing</li>\n// ]\ncy.get('ul').children('.active')"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Notes"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Shadow DOM boundaries and `.children()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`.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 "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/configuration.md#Global",
            "children": [
              {
                "type": "text",
                "value": "`includeShadowDom`"
              }
            ]
          },
          {
            "type": "text",
            "value": " is enabled, since that option applies to "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/get.md#Arguments",
            "children": [
              {
                "type": "text",
                "value": "`cy.get()`"
              }
            ]
          },
          {
            "type": "text",
            "value": ", "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/find.md#Arguments",
            "children": [
              {
                "type": "text",
                "value": "`.find()`"
              }
            ]
          },
          {
            "type": "text",
            "value": ", and "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/contains.md#Shadow-DOM",
            "children": [
              {
                "type": "text",
                "value": "`cy.contains()`"
              }
            ]
          },
          {
            "type": "text",
            "value": ". To query inside a shadow root, traverse into it with "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/shadow.md",
            "children": [
              {
                "type": "text",
                "value": "`.shadow()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " first."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Rules"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Requirements"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.children()` requires being chained off a command that yields DOM element(s) or a document."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Assertions"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.children()` will automatically "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "retry"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " until the element(s) "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Implicit-Assertions",
                    "children": [
                      {
                        "type": "text",
                        "value": "exist in the DOM"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.children()` will automatically "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "retry"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " until all chained assertions have passed."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Timeouts"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.children()` can time out waiting for the element(s) to "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Implicit-Assertions",
                    "children": [
                      {
                        "type": "text",
                        "value": "exist in the DOM"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.children()` can time out waiting for assertions you've added to pass."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Command Log"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Assert that there should be 8 children elements in a nav"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('.left-nav>.nav').children().should('have.length', 8)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The commands above will display in the Command Log as:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When clicking on the `children` command within the command log, the console outputs the following:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#12-6-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "12.6.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Overwrite `.children()` with "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/cypress-api/custom-queries.md#Overwriting-Existing-Queries",
                    "children": [
                      {
                        "type": "text",
                        "value": "`Cypress.Commands.overwriteQuery()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " rather than `Cypress.Commands.overwrite()`."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#12-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "12.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`.children()` is now a query."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/find.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.find()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/next.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.next()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/parent.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.parent()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/parents.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.parents()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/siblings.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.siblings()`"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 729
}