{
  "doc": {
    "id": "api/commands/parent",
    "title": "parent | Cypress Documentation",
    "description": "Get the parent DOM element of a set of DOM elements in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/parent.md",
    "version": "3cf5b86b3403f604bdf7f3e35025c3bc3865e02c",
    "updated_at": "2026-05-07T17:44:31.931Z",
    "headings": [
      {
        "id": "api/commands/parent#parent",
        "text": "parent",
        "level": 1
      },
      {
        "id": "api/commands/parent#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/parent#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/parent#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/parent#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/parent#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/parent#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/parent#get-the-parent-of-the-active-li",
        "text": "Get the parent of the active li",
        "level": 4
      },
      {
        "id": "api/commands/parent#selector",
        "text": "Selector",
        "level": 3
      },
      {
        "id": "api/commands/parent#get-the-parent-with-class-sub-nav-of-all-li-elements",
        "text": "Get the parent with class sub-nav of all li elements",
        "level": 4
      },
      {
        "id": "api/commands/parent#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/parent#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/parent#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/parent#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/parent#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/parent#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/parent#syntax",
      "doc_id": "api/commands/parent",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.parent().parent(selector).parent(options).parent(selector, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('header').parent() // Yield parent el of `header`\n```\n\n**Incorrect Usage**\n\n```\ncy.parent() // Errors, cannot be chained off 'cy'cy.reload().parent() // Errors, 'reload' does not yield DOM element\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 `.parent()`.\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 `.parent()` to resolve before [timing out](#Timeouts) |\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n*   `.parent()` yields the new DOM element(s) it found.\n*   `.parent()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 183
    },
    {
      "id": "api/commands/parent#usage",
      "doc_id": "api/commands/parent",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('header').parent() // Yield parent el of `header`\n```\n\n**Incorrect Usage**\n\n```\ncy.parent() // Errors, cannot be chained off 'cy'cy.reload().parent() // Errors, 'reload' does not yield DOM element\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 44
    },
    {
      "id": "api/commands/parent#arguments",
      "doc_id": "api/commands/parent",
      "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 `.parent()`.\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 `.parent()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 93
    },
    {
      "id": "api/commands/parent#examples",
      "doc_id": "api/commands/parent",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Args\n\n#### Get the parent of the active `li`\n\n```\n<ul class=\"main-nav\">  <li>Overview</li>  <li>    Getting started    <ul class=\"sub-nav\">      <li>Install</li>      <li class=\"active\">Build</li>      <li>Test</li>    </ul>  </li></ul>\n```\n\n```\n// yields .sub-navcy.get('li.active').parent()\n```\n\n### Selector\n\n#### Get the parent with class `sub-nav` of all `li` elements\n\n```\n<ul class=\"main-nav\">  <li>Overview</li>  <li>    Getting started    <ul class=\"sub-nav\">      <li>Install</li>      <li class=\"active\">Build</li>      <li>Test</li>    </ul>  </li></ul>\n```\n\n```\n// yields .sub-navcy.get('li').parent('.sub-nav')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 91
    },
    {
      "id": "api/commands/parent#no-args",
      "doc_id": "api/commands/parent",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Get the parent of the active `li`\n\n```\n<ul class=\"main-nav\">  <li>Overview</li>  <li>    Getting started    <ul class=\"sub-nav\">      <li>Install</li>      <li class=\"active\">Build</li>      <li>Test</li>    </ul>  </li></ul>\n```\n\n```\n// yields .sub-navcy.get('li.active').parent()\n```\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 43
    },
    {
      "id": "api/commands/parent#selector",
      "doc_id": "api/commands/parent",
      "heading": "Selector",
      "heading_level": 3,
      "content_markdown": "### Selector\n\n#### Get the parent with class `sub-nav` of all `li` elements\n\n```\n<ul class=\"main-nav\">  <li>Overview</li>  <li>    Getting started    <ul class=\"sub-nav\">      <li>Install</li>      <li class=\"active\">Build</li>      <li>Test</li>    </ul>  </li></ul>\n```\n\n```\n// yields .sub-navcy.get('li').parent('.sub-nav')\n```\n",
      "section": "api",
      "anchors": [
        "selector"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 45
    },
    {
      "id": "api/commands/parent#get-the-parent-with-class-sub-nav-of-all-li-elements",
      "doc_id": "api/commands/parent",
      "heading": "Get the parent with class sub-nav of all li elements",
      "heading_level": 4,
      "content_markdown": "#### Get the parent with class `sub-nav` of all `li` elements\n\n```\n<ul class=\"main-nav\">  <li>Overview</li>  <li>    Getting started    <ul class=\"sub-nav\">      <li>Install</li>      <li class=\"active\">Build</li>      <li>Test</li>    </ul>  </li></ul>\n```\n\n```\n// yields .sub-navcy.get('li').parent('.sub-nav')\n```\n",
      "section": "api",
      "anchors": [
        "get-the-parent-with-class-sub-nav-of-all-li-elements"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 43
    },
    {
      "id": "api/commands/parent#rules",
      "doc_id": "api/commands/parent",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `.parent()` requires being chained off a command that yields DOM element(s).\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `.parent()` 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*   `.parent()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.\n\n### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `.parent()` 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*   `.parent()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 105
    },
    {
      "id": "api/commands/parent#timeouts-learn-about-timeouts",
      "doc_id": "api/commands/parent",
      "heading": "Timeouts Learn about timeouts",
      "heading_level": 3,
      "content_markdown": "### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `.parent()` 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*   `.parent()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "timeouts-learn-about-timeouts"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 41
    },
    {
      "id": "api/commands/parent#command-log",
      "doc_id": "api/commands/parent",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Assert on the parent of the active li_**\n\n```\ncy.get('li.active').parent().should('have.class', 'nav')\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on the `parent` command within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/parent.json",
      "token_estimate": 53
    }
  ]
}