{
  "doc": {
    "id": "api/commands/prev",
    "title": "cy.prev()",
    "description": "Get the immediately preceding sibling of each element in a set of the elements in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/prev.md",
    "version": "f60251bf707b0077a9535579c9f90d615440cc35",
    "updated_at": "2026-10-16T10:56:58.670Z",
    "headings": [
      {
        "id": "api/commands/prev#prev",
        "text": "prev",
        "level": 1
      },
      {
        "id": "api/commands/prev#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/prev#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/prev#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/prev#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/prev#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/prev#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/prev#find-the-previous-element-of-the-element-with-class-of-active",
        "text": "Find the previous element of the element with class of active",
        "level": 4
      },
      {
        "id": "api/commands/prev#selector",
        "text": "Selector",
        "level": 3
      },
      {
        "id": "api/commands/prev#find-the-previous-element-with-a-class-of-active",
        "text": "Find the previous element with a class of active",
        "level": 4
      },
      {
        "id": "api/commands/prev#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/prev#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/prev#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/prev#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/prev#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/prev#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/prev#syntax",
      "doc_id": "api/commands/prev",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.prev()\n.prev(selector)\n.prev(options)\n.prev(selector, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('tr.highlight').prev() // Yield previous 'tr'\n```\n\n**Incorrect Usage**\n\n```\ncy.prev() // Errors, cannot be chained off 'cy'\ncy.getCookies().prev() // Errors, 'getCookies' 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 `.prev()`.\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 `.prev()` to resolve before [timing out](#Timeouts) |\n\n### Yields\n\n*   `.prev()` yields the new DOM element(s) it found.\n*   `.prev()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/prev.json",
      "token_estimate": 180
    },
    {
      "id": "api/commands/prev#usage",
      "doc_id": "api/commands/prev",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('tr.highlight').prev() // Yield previous 'tr'\n```\n\n**Incorrect Usage**\n\n```\ncy.prev() // Errors, cannot be chained off 'cy'\ncy.getCookies().prev() // Errors, 'getCookies' does not yield DOM element\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/prev.json",
      "token_estimate": 43
    },
    {
      "id": "api/commands/prev#arguments",
      "doc_id": "api/commands/prev",
      "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 `.prev()`.\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 `.prev()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/prev.json",
      "token_estimate": 93
    },
    {
      "id": "api/commands/prev#examples",
      "doc_id": "api/commands/prev",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Args\n\n#### Find the previous element of the element with class of `active`\n\n```\n<ul>\n  <li>Cockatiels</li>\n  <li>Lorikeets</li>\n  <li class=\"active\">Cockatoos</li>\n  <li>Conures</li>\n  <li>Eclectus</li>\n</ul>\n```\n\n```\n// yields <li>Lorikeets</li>\ncy.get('.active').prev()\n```\n\n### Selector\n\n#### Find the previous element with a class of `active`\n\n```\n<ul>\n  <li>Cockatiels</li>\n  <li>Lorikeets</li>\n  <li class=\"active\">Cockatoos</li>\n  <li>Conures</li>\n  <li>Eclectus</li>\n</ul>\n```\n\n```\n// yields <li>Cockatoos</li>\ncy.get('li').prev('.active')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/prev.json",
      "token_estimate": 81
    },
    {
      "id": "api/commands/prev#no-args",
      "doc_id": "api/commands/prev",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Find the previous element of the element with class of `active`\n\n```\n<ul>\n  <li>Cockatiels</li>\n  <li>Lorikeets</li>\n  <li class=\"active\">Cockatoos</li>\n  <li>Conures</li>\n  <li>Eclectus</li>\n</ul>\n```\n\n```\n// yields <li>Lorikeets</li>\ncy.get('.active').prev()\n```\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/prev.json",
      "token_estimate": 41
    },
    {
      "id": "api/commands/prev#rules",
      "doc_id": "api/commands/prev",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `.prev()` requires being chained off a command that yields DOM element(s) or a document.\n\n### Assertions\n\n*   `.prev()` 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*   `.prev()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.\n\n### Timeouts\n\n*   `.prev()` 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*   `.prev()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/prev.json",
      "token_estimate": 96
    },
    {
      "id": "api/commands/prev#command-log",
      "doc_id": "api/commands/prev",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Find the previous element of the active `li`_**\n\n```\ncy.get('.left-nav').find('li.active').prev()\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on `prev` within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/prev.json",
      "token_estimate": 49
    }
  ]
}