{
  "doc": {
    "id": "api/commands/filter",
    "title": "cy.filter()",
    "description": "Get the DOM elements that match a specific selector in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/filter.md",
    "version": "c4ad6f88c531de58221c73dd91a75af7138334b8",
    "updated_at": "2026-11-10T01:15:02.829Z",
    "headings": [
      {
        "id": "api/commands/filter#filter",
        "text": "filter",
        "level": 1
      },
      {
        "id": "api/commands/filter#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/filter#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/filter#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/filter#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/filter#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/filter#selector",
        "text": "Selector",
        "level": 3
      },
      {
        "id": "api/commands/filter#filter-list-items-by-class-name-with-filter",
        "text": "Filter list items by class name with .filter()",
        "level": 4
      },
      {
        "id": "api/commands/filter#filter-elements-by-attribute-value-with-filter",
        "text": "Filter elements by attribute value with .filter()",
        "level": 4
      },
      {
        "id": "api/commands/filter#filter-form-controls-by-checked-or-disabled-state",
        "text": "Filter form controls by checked or disabled state",
        "level": 4
      },
      {
        "id": "api/commands/filter#filter-to-visible-elements-with-the-visible-selector",
        "text": "Filter to visible elements with the :visible selector",
        "level": 4
      },
      {
        "id": "api/commands/filter#function",
        "text": "Function",
        "level": 3
      },
      {
        "id": "api/commands/filter#filter-elements-with-a-test-function-in-filter",
        "text": "Filter elements with a test function in .filter()",
        "level": 4
      },
      {
        "id": "api/commands/filter#filter-elements-by-a-numeric-value-with-a-function",
        "text": "Filter elements by a numeric value with a function",
        "level": 4
      },
      {
        "id": "api/commands/filter#filter-elements-by-text-without-matching-case",
        "text": "Filter elements by text without matching case",
        "level": 4
      },
      {
        "id": "api/commands/filter#contains",
        "text": "Contains",
        "level": 3
      },
      {
        "id": "api/commands/filter#filter-elements-by-text-with-the-contains-selector",
        "text": "Filter elements by text with the :contains selector",
        "level": 4
      },
      {
        "id": "api/commands/filter#filter-table-rows-by-a-cells-text-with-has",
        "text": "Filter table rows by a cell's text with :has()",
        "level": 4
      },
      {
        "id": "api/commands/filter#match-a-non-breaking-space-with-contains-in-filter",
        "text": "Match a non-breaking space with :contains in .filter()",
        "level": 4
      },
      {
        "id": "api/commands/filter#actions-and-assertions",
        "text": "Actions and assertions",
        "level": 3
      },
      {
        "id": "api/commands/filter#click-one-element-from-a-filter-result",
        "text": "Click one element from a .filter() result",
        "level": 4
      },
      {
        "id": "api/commands/filter#assert-that-no-elements-match-a-filter-selector",
        "text": "Assert that no elements match a .filter() selector",
        "level": 4
      },
      {
        "id": "api/commands/filter#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/filter#choosing-between-filter-find-and-contains",
        "text": "Choosing between .filter(), .find(), and .contains()",
        "level": 3
      },
      {
        "id": "api/commands/filter#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/filter#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/filter#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/filter#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/filter#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/filter#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/filter#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/filter#syntax",
      "doc_id": "api/commands/filter",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.filter(selector)\n.filter(selector, options)\n.filter(fn)\n.filter(fn, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('td').filter('.users') // Yield all el's with class '.users'\n```\n\n**Incorrect Usage**\n\n```\ncy.filter('.animated') // Errors, cannot be chained off 'cy'\ncy.clock().filter() // 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**fn _(Function)_**\n\nA function called once for each element in the subject, with the element's index and the element itself as arguments: `(index, element)`. `.filter()` yields the elements for which the function returns a truthy value.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.filter()`.\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 `.filter()` to resolve before [timing out](#Timeouts) |\n\n### Yields\n\n*   `.filter()` yields the new DOM element(s) it found.\n*   `.filter()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 233
    },
    {
      "id": "api/commands/filter#usage",
      "doc_id": "api/commands/filter",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('td').filter('.users') // Yield all el's with class '.users'\n```\n\n**Incorrect Usage**\n\n```\ncy.filter('.animated') // Errors, cannot be chained off 'cy'\ncy.clock().filter() // Errors, 'clock' does not yield DOM elements\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 47
    },
    {
      "id": "api/commands/filter#arguments",
      "doc_id": "api/commands/filter",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**selector _(String selector)_**\n\nA selector used to filter matching DOM elements.\n\n**fn _(Function)_**\n\nA function called once for each element in the subject, with the element's index and the element itself as arguments: `(index, element)`. `.filter()` yields the elements for which the function returns a truthy value.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.filter()`.\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 `.filter()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 141
    },
    {
      "id": "api/commands/filter#examples",
      "doc_id": "api/commands/filter",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### Selector\n\n#### Filter list items by class name with `.filter()`\n\nindex.html\n\n```\n<ul>\n  <li>Home</li>\n  <li class=\"active\">About</li>\n  <li>Services</li>\n  <li>Pricing</li>\n  <li>Contact</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// yields <li>About</li>\ncy.get('ul').find('>li').filter('.active')\n```\n\n#### Filter elements by attribute value with `.filter()`\n\nindex.html\n\n```\n<table>\n  <tr data-cy=\"order-row\" data-status=\"shipped\">\n    <td>#1001</td>\n  </tr>\n  <tr data-cy=\"order-row\" data-status=\"pending\">\n    <td>#1002</td>\n  </tr>\n  <tr data-cy=\"order-row\" data-status=\"shipped\">\n    <td>#1003</td>\n  </tr>\n</table>\n```\n\nspec.cy.js\n\n```\n// yields the rows for orders #1001 and #1003\ncy.get('[data-cy=\"order-row\"]')\n  .filter('[data-status=\"shipped\"]')\n  .should('have.length', 2)\n```\n\n#### Filter form controls by checked or disabled state\n\nStandard CSS pseudo-classes such as `:checked`, `:disabled`, and `:enabled` narrow form controls by their current state.\n\nindex.html\n\n```\n<input type=\"checkbox\" name=\"email\" checked />\n<input type=\"checkbox\" name=\"sms\" />\n<input type=\"checkbox\" name=\"push\" checked />\n```\n\nspec.cy.js\n\n```\ncy.get('input[type=\"checkbox\"]').filter(':checked').should('have.length', 2)\n```\n\n#### Filter to visible elements with the `:visible` selector\n\nCypress replaces jQuery's `:visible` and `:hidden` selectors with its own [visibility rules](/llm/markdown/app/core-concepts/interacting-with-elements.md#Visibility), so `.filter(':visible')` keeps exactly the elements that `.should('be.visible')` treats as visible. Cypress also adds a `:focused` selector that matches the focused element.\n\nindex.html\n\n```\n<ul class=\"menu\">\n  <li>Dashboard</li>\n  <li>Reports</li>\n  <li style=\"display: none\">Admin</li>\n  <li>Settings</li>\n</ul>\n```\n\nspec.cy.js\n\n```\ncy.get('.menu li').filter(':visible').should('have.length', 3)\n```\n\n### Function\n\n#### Filter elements with a test function in `.filter()`\n\nindex.html\n\n```\n<ul>\n  <li>Home</li>\n  <li class=\"active\">About</li>\n  <li>Services</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// yields <li>Home</li> and <li>Services</li>\ncy.get('li').filter((index, el) => !el.classList.contains('active'))\n```\n\nspec.cy.js\n\n```\n// yields the even-indexed <li> elements: Home and Services\ncy.get('li').filter((index) => index % 2 === 0)\n```\n\nBecause `.filter()` is a query, Cypress calls the function again on every [retry](/llm/markdown/app/core-concepts/retry-ability.md). Keep it synchronous and free of side effects, and don't call other Cypress commands inside it.\n\nRead the element from the function's second argument rather than from `this`. Arrow functions don't bind `this`, so `el` works in every function style.\n\n#### Filter elements by a numeric value with a function\n\nA selector can't compare numbers, but a function can.\n\nindex.html\n\n```\n<ul>\n  <li class=\"price\">$45.00</li>\n  <li class=\"price\">$120.00</li>\n  <li class=\"price\">$310.50</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// yields the $120.00 and $310.50 prices\ncy.get('.price')\n  .filter((index, el) => parseFloat(el.textContent.replace('$', '')) > 100)\n  .should('have.length', 2)\n```\n\n#### Filter elements by text without matching case\n\nThe `:contains` selector is case-sensitive. Compare lowercased text in a function to match regardless of case.\n\nindex.html\n\n```\n<ul>\n  <li>Services</li>\n  <li>Advanced services</li>\n  <li>Pricing</li>\n</ul>\n```\n\nspec.cy.js\n\n```\ncy.get('li')\n  .filter((index, el) => el.textContent.toLowerCase().includes('services'))\n  .should('have.length', 2)\n```\n\nTo get a single element by text regardless of case, use [`.contains()`](/llm/markdown/api/commands/contains.md) with the `matchCase: false` option.\n\n### Contains\n\n#### Filter elements by text with the `:contains` selector\n\nYou can use the [jQuery :contains](https://api.jquery.com/contains-selector/) selector to perform a case-sensitive text substring match.\n\nindex.html\n\n```\n<ul>\n  <li>Home</li>\n  <li>Services</li>\n  <li>Advanced Services</li>\n  <li>Pricing</li>\n  <li>Contact</li>\n</ul>\n```\n\nFind both list items that contain the word \"Services\":\n\nspec.cy.js\n\n```\ncy.get('li').filter(':contains(\"Services\")').should('have.length', 2)\n```\n\n#### Filter table rows by a cell's text with `:has()`\n\nCombine the [jQuery :has](https://api.jquery.com/has-selector/) selector with `:contains` to keep only the rows with a matching cell, then act on something inside that row.\n\nindex.html\n\n```\n<table>\n  <tbody>\n    <tr>\n      <td>Ana</td>\n      <td>Admin</td>\n      <td><button class=\"edit\">Edit</button></td>\n    </tr>\n    <tr>\n      <td>Ben</td>\n      <td>Viewer</td>\n      <td><button class=\"edit\">Edit</button></td>\n    </tr>\n  </tbody>\n</table>\n```\n\nspec.cy.js\n\n```\ncy.get('tbody tr')\n  .filter(':has(td:contains(\"Admin\"))')\n  .find('button.edit')\n  .click()\n```\n\n#### Match a non-breaking space with `:contains` in `.filter()`\n\nIf the HTML contains a [non-breaking space](https://en.wikipedia.org/wiki/Non-breaking_space) entity `&nbsp;` and the test uses the [jQuery :contains](https://api.jquery.com/contains-selector/) selector, then the test needs to use the Unicode value `\\u00a0` instead of `&nbsp;`.\n\nindex.html\n\n```\n<div data-testid=\"testattr\">\n  <span>Hello&nbsp;world</span>\n</div>\n```\n\nspec.cy.js\n\n```\ncy.get('[data-testid=\"testattr\"]').filter(':contains(\"Hello\\u00a0world\")')\n```\n\n### Actions and assertions\n\n#### Click one element from a `.filter()` result\n\n`.filter()` can yield several elements, and action commands such as [`.click()`](/llm/markdown/api/commands/click.md) fail on more than one element unless you pass `{ multiple: true }`. Narrow the result to a single element first with [`.first()`](/llm/markdown/api/commands/first.md), [`.last()`](/llm/markdown/api/commands/last.md), or [`.eq()`](/llm/markdown/api/commands/eq.md).\n\nindex.html\n\n```\n<ul>\n  <li><button class=\"delete\">Delete</button> Draft 1</li>\n  <li><button class=\"delete\" disabled>Delete</button> Published post</li>\n  <li><button class=\"delete\">Delete</button> Draft 2</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// clicks the Delete button for Draft 1\ncy.get('button.delete').filter(':enabled').first().click()\n```\n\n#### Assert that no elements match a `.filter()` selector\n\nindex.html\n\n```\n<ul>\n  <li class=\"notification info\">Saved</li>\n  <li class=\"notification info\">Synced</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// passes once no notification has the 'error' class\ncy.get('.notification').filter('.error').should('not.exist')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 892
    },
    {
      "id": "api/commands/filter#selector",
      "doc_id": "api/commands/filter",
      "heading": "Selector",
      "heading_level": 3,
      "content_markdown": "### Selector\n\n#### Filter list items by class name with `.filter()`\n\nindex.html\n\n```\n<ul>\n  <li>Home</li>\n  <li class=\"active\">About</li>\n  <li>Services</li>\n  <li>Pricing</li>\n  <li>Contact</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// yields <li>About</li>\ncy.get('ul').find('>li').filter('.active')\n```\n\n#### Filter elements by attribute value with `.filter()`\n\nindex.html\n\n```\n<table>\n  <tr data-cy=\"order-row\" data-status=\"shipped\">\n    <td>#1001</td>\n  </tr>\n  <tr data-cy=\"order-row\" data-status=\"pending\">\n    <td>#1002</td>\n  </tr>\n  <tr data-cy=\"order-row\" data-status=\"shipped\">\n    <td>#1003</td>\n  </tr>\n</table>\n```\n\nspec.cy.js\n\n```\n// yields the rows for orders #1001 and #1003\ncy.get('[data-cy=\"order-row\"]')\n  .filter('[data-status=\"shipped\"]')\n  .should('have.length', 2)\n```\n\n#### Filter form controls by checked or disabled state\n\nStandard CSS pseudo-classes such as `:checked`, `:disabled`, and `:enabled` narrow form controls by their current state.\n\nindex.html\n\n```\n<input type=\"checkbox\" name=\"email\" checked />\n<input type=\"checkbox\" name=\"sms\" />\n<input type=\"checkbox\" name=\"push\" checked />\n```\n\nspec.cy.js\n\n```\ncy.get('input[type=\"checkbox\"]').filter(':checked').should('have.length', 2)\n```\n\n#### Filter to visible elements with the `:visible` selector\n\nCypress replaces jQuery's `:visible` and `:hidden` selectors with its own [visibility rules](/llm/markdown/app/core-concepts/interacting-with-elements.md#Visibility), so `.filter(':visible')` keeps exactly the elements that `.should('be.visible')` treats as visible. Cypress also adds a `:focused` selector that matches the focused element.\n\nindex.html\n\n```\n<ul class=\"menu\">\n  <li>Dashboard</li>\n  <li>Reports</li>\n  <li style=\"display: none\">Admin</li>\n  <li>Settings</li>\n</ul>\n```\n\nspec.cy.js\n\n```\ncy.get('.menu li').filter(':visible').should('have.length', 3)\n```\n",
      "section": "api",
      "anchors": [
        "selector"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 241
    },
    {
      "id": "api/commands/filter#filter-elements-by-attribute-value-with-filter",
      "doc_id": "api/commands/filter",
      "heading": "Filter elements by attribute value with .filter()",
      "heading_level": 4,
      "content_markdown": "#### Filter elements by attribute value with `.filter()`\n\nindex.html\n\n```\n<table>\n  <tr data-cy=\"order-row\" data-status=\"shipped\">\n    <td>#1001</td>\n  </tr>\n  <tr data-cy=\"order-row\" data-status=\"pending\">\n    <td>#1002</td>\n  </tr>\n  <tr data-cy=\"order-row\" data-status=\"shipped\">\n    <td>#1003</td>\n  </tr>\n</table>\n```\n\nspec.cy.js\n\n```\n// yields the rows for orders #1001 and #1003\ncy.get('[data-cy=\"order-row\"]')\n  .filter('[data-status=\"shipped\"]')\n  .should('have.length', 2)\n```\n",
      "section": "api",
      "anchors": [
        "filter-elements-by-attribute-value-with-filter"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 59
    },
    {
      "id": "api/commands/filter#filter-form-controls-by-checked-or-disabled-state",
      "doc_id": "api/commands/filter",
      "heading": "Filter form controls by checked or disabled state",
      "heading_level": 4,
      "content_markdown": "#### Filter form controls by checked or disabled state\n\nStandard CSS pseudo-classes such as `:checked`, `:disabled`, and `:enabled` narrow form controls by their current state.\n\nindex.html\n\n```\n<input type=\"checkbox\" name=\"email\" checked />\n<input type=\"checkbox\" name=\"sms\" />\n<input type=\"checkbox\" name=\"push\" checked />\n```\n\nspec.cy.js\n\n```\ncy.get('input[type=\"checkbox\"]').filter(':checked').should('have.length', 2)\n```\n",
      "section": "api",
      "anchors": [
        "filter-form-controls-by-checked-or-disabled-state"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 63
    },
    {
      "id": "api/commands/filter#filter-to-visible-elements-with-the-visible-selector",
      "doc_id": "api/commands/filter",
      "heading": "Filter to visible elements with the :visible selector",
      "heading_level": 4,
      "content_markdown": "#### Filter to visible elements with the `:visible` selector\n\nCypress replaces jQuery's `:visible` and `:hidden` selectors with its own [visibility rules](/llm/markdown/app/core-concepts/interacting-with-elements.md#Visibility), so `.filter(':visible')` keeps exactly the elements that `.should('be.visible')` treats as visible. Cypress also adds a `:focused` selector that matches the focused element.\n\nindex.html\n\n```\n<ul class=\"menu\">\n  <li>Dashboard</li>\n  <li>Reports</li>\n  <li style=\"display: none\">Admin</li>\n  <li>Settings</li>\n</ul>\n```\n\nspec.cy.js\n\n```\ncy.get('.menu li').filter(':visible').should('have.length', 3)\n```\n",
      "section": "api",
      "anchors": [
        "filter-to-visible-elements-with-the-visible-selector"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 81
    },
    {
      "id": "api/commands/filter#function",
      "doc_id": "api/commands/filter",
      "heading": "Function",
      "heading_level": 3,
      "content_markdown": "### Function\n\n#### Filter elements with a test function in `.filter()`\n\nindex.html\n\n```\n<ul>\n  <li>Home</li>\n  <li class=\"active\">About</li>\n  <li>Services</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// yields <li>Home</li> and <li>Services</li>\ncy.get('li').filter((index, el) => !el.classList.contains('active'))\n```\n\nspec.cy.js\n\n```\n// yields the even-indexed <li> elements: Home and Services\ncy.get('li').filter((index) => index % 2 === 0)\n```\n\nBecause `.filter()` is a query, Cypress calls the function again on every [retry](/llm/markdown/app/core-concepts/retry-ability.md). Keep it synchronous and free of side effects, and don't call other Cypress commands inside it.\n\nRead the element from the function's second argument rather than from `this`. Arrow functions don't bind `this`, so `el` works in every function style.\n\n#### Filter elements by a numeric value with a function\n\nA selector can't compare numbers, but a function can.\n\nindex.html\n\n```\n<ul>\n  <li class=\"price\">$45.00</li>\n  <li class=\"price\">$120.00</li>\n  <li class=\"price\">$310.50</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// yields the $120.00 and $310.50 prices\ncy.get('.price')\n  .filter((index, el) => parseFloat(el.textContent.replace('$', '')) > 100)\n  .should('have.length', 2)\n```\n\n#### Filter elements by text without matching case\n\nThe `:contains` selector is case-sensitive. Compare lowercased text in a function to match regardless of case.\n\nindex.html\n\n```\n<ul>\n  <li>Services</li>\n  <li>Advanced services</li>\n  <li>Pricing</li>\n</ul>\n```\n\nspec.cy.js\n\n```\ncy.get('li')\n  .filter((index, el) => el.textContent.toLowerCase().includes('services'))\n  .should('have.length', 2)\n```\n\nTo get a single element by text regardless of case, use [`.contains()`](/llm/markdown/api/commands/contains.md) with the `matchCase: false` option.\n",
      "section": "api",
      "anchors": [
        "function"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 285
    },
    {
      "id": "api/commands/filter#filter-elements-with-a-test-function-in-filter",
      "doc_id": "api/commands/filter",
      "heading": "Filter elements with a test function in .filter()",
      "heading_level": 4,
      "content_markdown": "#### Filter elements with a test function in `.filter()`\n\nindex.html\n\n```\n<ul>\n  <li>Home</li>\n  <li class=\"active\">About</li>\n  <li>Services</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// yields <li>Home</li> and <li>Services</li>\ncy.get('li').filter((index, el) => !el.classList.contains('active'))\n```\n\nspec.cy.js\n\n```\n// yields the even-indexed <li> elements: Home and Services\ncy.get('li').filter((index) => index % 2 === 0)\n```\n\nBecause `.filter()` is a query, Cypress calls the function again on every [retry](/llm/markdown/app/core-concepts/retry-ability.md). Keep it synchronous and free of side effects, and don't call other Cypress commands inside it.\n\nRead the element from the function's second argument rather than from `this`. Arrow functions don't bind `this`, so `el` works in every function style.\n",
      "section": "api",
      "anchors": [
        "filter-elements-with-a-test-function-in-filter"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 136
    },
    {
      "id": "api/commands/filter#filter-elements-by-a-numeric-value-with-a-function",
      "doc_id": "api/commands/filter",
      "heading": "Filter elements by a numeric value with a function",
      "heading_level": 4,
      "content_markdown": "#### Filter elements by a numeric value with a function\n\nA selector can't compare numbers, but a function can.\n\nindex.html\n\n```\n<ul>\n  <li class=\"price\">$45.00</li>\n  <li class=\"price\">$120.00</li>\n  <li class=\"price\">$310.50</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// yields the $120.00 and $310.50 prices\ncy.get('.price')\n  .filter((index, el) => parseFloat(el.textContent.replace('$', '')) > 100)\n  .should('have.length', 2)\n```\n",
      "section": "api",
      "anchors": [
        "filter-elements-by-a-numeric-value-with-a-function"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 67
    },
    {
      "id": "api/commands/filter#filter-elements-by-text-without-matching-case",
      "doc_id": "api/commands/filter",
      "heading": "Filter elements by text without matching case",
      "heading_level": 4,
      "content_markdown": "#### Filter elements by text without matching case\n\nThe `:contains` selector is case-sensitive. Compare lowercased text in a function to match regardless of case.\n\nindex.html\n\n```\n<ul>\n  <li>Services</li>\n  <li>Advanced services</li>\n  <li>Pricing</li>\n</ul>\n```\n\nspec.cy.js\n\n```\ncy.get('li')\n  .filter((index, el) => el.textContent.toLowerCase().includes('services'))\n  .should('have.length', 2)\n```\n\nTo get a single element by text regardless of case, use [`.contains()`](/llm/markdown/api/commands/contains.md) with the `matchCase: false` option.\n",
      "section": "api",
      "anchors": [
        "filter-elements-by-text-without-matching-case"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 80
    },
    {
      "id": "api/commands/filter#contains",
      "doc_id": "api/commands/filter",
      "heading": "Contains",
      "heading_level": 3,
      "content_markdown": "### Contains\n\n#### Filter elements by text with the `:contains` selector\n\nYou can use the [jQuery :contains](https://api.jquery.com/contains-selector/) selector to perform a case-sensitive text substring match.\n\nindex.html\n\n```\n<ul>\n  <li>Home</li>\n  <li>Services</li>\n  <li>Advanced Services</li>\n  <li>Pricing</li>\n  <li>Contact</li>\n</ul>\n```\n\nFind both list items that contain the word \"Services\":\n\nspec.cy.js\n\n```\ncy.get('li').filter(':contains(\"Services\")').should('have.length', 2)\n```\n\n#### Filter table rows by a cell's text with `:has()`\n\nCombine the [jQuery :has](https://api.jquery.com/has-selector/) selector with `:contains` to keep only the rows with a matching cell, then act on something inside that row.\n\nindex.html\n\n```\n<table>\n  <tbody>\n    <tr>\n      <td>Ana</td>\n      <td>Admin</td>\n      <td><button class=\"edit\">Edit</button></td>\n    </tr>\n    <tr>\n      <td>Ben</td>\n      <td>Viewer</td>\n      <td><button class=\"edit\">Edit</button></td>\n    </tr>\n  </tbody>\n</table>\n```\n\nspec.cy.js\n\n```\ncy.get('tbody tr')\n  .filter(':has(td:contains(\"Admin\"))')\n  .find('button.edit')\n  .click()\n```\n\n#### Match a non-breaking space with `:contains` in `.filter()`\n\nIf the HTML contains a [non-breaking space](https://en.wikipedia.org/wiki/Non-breaking_space) entity `&nbsp;` and the test uses the [jQuery :contains](https://api.jquery.com/contains-selector/) selector, then the test needs to use the Unicode value `\\u00a0` instead of `&nbsp;`.\n\nindex.html\n\n```\n<div data-testid=\"testattr\">\n  <span>Hello&nbsp;world</span>\n</div>\n```\n\nspec.cy.js\n\n```\ncy.get('[data-testid=\"testattr\"]').filter(':contains(\"Hello\\u00a0world\")')\n```\n",
      "section": "api",
      "anchors": [
        "contains"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 213
    },
    {
      "id": "api/commands/filter#filter-elements-by-text-with-the-contains-selector",
      "doc_id": "api/commands/filter",
      "heading": "Filter elements by text with the :contains selector",
      "heading_level": 4,
      "content_markdown": "#### Filter elements by text with the `:contains` selector\n\nYou can use the [jQuery :contains](https://api.jquery.com/contains-selector/) selector to perform a case-sensitive text substring match.\n\nindex.html\n\n```\n<ul>\n  <li>Home</li>\n  <li>Services</li>\n  <li>Advanced Services</li>\n  <li>Pricing</li>\n  <li>Contact</li>\n</ul>\n```\n\nFind both list items that contain the word \"Services\":\n\nspec.cy.js\n\n```\ncy.get('li').filter(':contains(\"Services\")').should('have.length', 2)\n```\n",
      "section": "api",
      "anchors": [
        "filter-elements-by-text-with-the-contains-selector"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 64
    },
    {
      "id": "api/commands/filter#filter-table-rows-by-a-cells-text-with-has",
      "doc_id": "api/commands/filter",
      "heading": "Filter table rows by a cell's text with :has()",
      "heading_level": 4,
      "content_markdown": "#### Filter table rows by a cell's text with `:has()`\n\nCombine the [jQuery :has](https://api.jquery.com/has-selector/) selector with `:contains` to keep only the rows with a matching cell, then act on something inside that row.\n\nindex.html\n\n```\n<table>\n  <tbody>\n    <tr>\n      <td>Ana</td>\n      <td>Admin</td>\n      <td><button class=\"edit\">Edit</button></td>\n    </tr>\n    <tr>\n      <td>Ben</td>\n      <td>Viewer</td>\n      <td><button class=\"edit\">Edit</button></td>\n    </tr>\n  </tbody>\n</table>\n```\n\nspec.cy.js\n\n```\ncy.get('tbody tr')\n  .filter(':has(td:contains(\"Admin\"))')\n  .find('button.edit')\n  .click()\n```\n",
      "section": "api",
      "anchors": [
        "filter-table-rows-by-a-cells-text-with-has"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 80
    },
    {
      "id": "api/commands/filter#match-a-non-breaking-space-with-contains-in-filter",
      "doc_id": "api/commands/filter",
      "heading": "Match a non-breaking space with :contains in .filter()",
      "heading_level": 4,
      "content_markdown": "#### Match a non-breaking space with `:contains` in `.filter()`\n\nIf the HTML contains a [non-breaking space](https://en.wikipedia.org/wiki/Non-breaking_space) entity `&nbsp;` and the test uses the [jQuery :contains](https://api.jquery.com/contains-selector/) selector, then the test needs to use the Unicode value `\\u00a0` instead of `&nbsp;`.\n\nindex.html\n\n```\n<div data-testid=\"testattr\">\n  <span>Hello&nbsp;world</span>\n</div>\n```\n\nspec.cy.js\n\n```\ncy.get('[data-testid=\"testattr\"]').filter(':contains(\"Hello\\u00a0world\")')\n```\n",
      "section": "api",
      "anchors": [
        "match-a-non-breaking-space-with-contains-in-filter"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 67
    },
    {
      "id": "api/commands/filter#actions-and-assertions",
      "doc_id": "api/commands/filter",
      "heading": "Actions and assertions",
      "heading_level": 3,
      "content_markdown": "### Actions and assertions\n\n#### Click one element from a `.filter()` result\n\n`.filter()` can yield several elements, and action commands such as [`.click()`](/llm/markdown/api/commands/click.md) fail on more than one element unless you pass `{ multiple: true }`. Narrow the result to a single element first with [`.first()`](/llm/markdown/api/commands/first.md), [`.last()`](/llm/markdown/api/commands/last.md), or [`.eq()`](/llm/markdown/api/commands/eq.md).\n\nindex.html\n\n```\n<ul>\n  <li><button class=\"delete\">Delete</button> Draft 1</li>\n  <li><button class=\"delete\" disabled>Delete</button> Published post</li>\n  <li><button class=\"delete\">Delete</button> Draft 2</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// clicks the Delete button for Draft 1\ncy.get('button.delete').filter(':enabled').first().click()\n```\n\n#### Assert that no elements match a `.filter()` selector\n\nindex.html\n\n```\n<ul>\n  <li class=\"notification info\">Saved</li>\n  <li class=\"notification info\">Synced</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// passes once no notification has the 'error' class\ncy.get('.notification').filter('.error').should('not.exist')\n```\n",
      "section": "api",
      "anchors": [
        "actions-and-assertions"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 149
    },
    {
      "id": "api/commands/filter#click-one-element-from-a-filter-result",
      "doc_id": "api/commands/filter",
      "heading": "Click one element from a .filter() result",
      "heading_level": 4,
      "content_markdown": "#### Click one element from a `.filter()` result\n\n`.filter()` can yield several elements, and action commands such as [`.click()`](/llm/markdown/api/commands/click.md) fail on more than one element unless you pass `{ multiple: true }`. Narrow the result to a single element first with [`.first()`](/llm/markdown/api/commands/first.md), [`.last()`](/llm/markdown/api/commands/last.md), or [`.eq()`](/llm/markdown/api/commands/eq.md).\n\nindex.html\n\n```\n<ul>\n  <li><button class=\"delete\">Delete</button> Draft 1</li>\n  <li><button class=\"delete\" disabled>Delete</button> Published post</li>\n  <li><button class=\"delete\">Delete</button> Draft 2</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// clicks the Delete button for Draft 1\ncy.get('button.delete').filter(':enabled').first().click()\n```\n",
      "section": "api",
      "anchors": [
        "click-one-element-from-a-filter-result"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 100
    },
    {
      "id": "api/commands/filter#assert-that-no-elements-match-a-filter-selector",
      "doc_id": "api/commands/filter",
      "heading": "Assert that no elements match a .filter() selector",
      "heading_level": 4,
      "content_markdown": "#### Assert that no elements match a `.filter()` selector\n\nindex.html\n\n```\n<ul>\n  <li class=\"notification info\">Saved</li>\n  <li class=\"notification info\">Synced</li>\n</ul>\n```\n\nspec.cy.js\n\n```\n// passes once no notification has the 'error' class\ncy.get('.notification').filter('.error').should('not.exist')\n```\n",
      "section": "api",
      "anchors": [
        "assert-that-no-elements-match-a-filter-selector"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 44
    },
    {
      "id": "api/commands/filter#notes",
      "doc_id": "api/commands/filter",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Choosing between `.filter()`, `.find()`, and `.contains()`\n\nThese three commands narrow a selection in different ways:\n\n*   `.filter()` keeps the elements in the current subject that match. It never looks inside them.\n*   [`.find()`](/llm/markdown/api/commands/find.md) searches the descendants of the current subject.\n*   [`.contains()`](/llm/markdown/api/commands/contains.md) matches by text and yields the deepest element that contains it.\n\nindex.html\n\n```\n<ul>\n  <li class=\"active\">About <span class=\"badge\">New</span></li>\n  <li>Services</li>\n</ul>\n```\n\nspec.cy.js\n\n```\ncy.get('li').filter('.active') // yields <li class=\"active\">\ncy.get('li').find('.badge') // yields <span class=\"badge\">\ncy.get('ul').contains('Services') // yields <li>Services</li>\n```\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 111
    },
    {
      "id": "api/commands/filter#choosing-between-filter-find-and-contains",
      "doc_id": "api/commands/filter",
      "heading": "Choosing between .filter(), .find(), and .contains()",
      "heading_level": 3,
      "content_markdown": "### Choosing between `.filter()`, `.find()`, and `.contains()`\n\nThese three commands narrow a selection in different ways:\n\n*   `.filter()` keeps the elements in the current subject that match. It never looks inside them.\n*   [`.find()`](/llm/markdown/api/commands/find.md) searches the descendants of the current subject.\n*   [`.contains()`](/llm/markdown/api/commands/contains.md) matches by text and yields the deepest element that contains it.\n\nindex.html\n\n```\n<ul>\n  <li class=\"active\">About <span class=\"badge\">New</span></li>\n  <li>Services</li>\n</ul>\n```\n\nspec.cy.js\n\n```\ncy.get('li').filter('.active') // yields <li class=\"active\">\ncy.get('li').find('.badge') // yields <span class=\"badge\">\ncy.get('ul').contains('Services') // yields <li>Services</li>\n```\n",
      "section": "api",
      "anchors": [
        "choosing-between-filter-find-and-contains"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 108
    },
    {
      "id": "api/commands/filter#rules",
      "doc_id": "api/commands/filter",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `.filter()` requires being chained off a command that yields DOM element(s) or a document.\n\n### Assertions\n\n*   `.filter()` 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*   `.filter()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.\n\n### Timeouts\n\n*   `.filter()` 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*   `.filter()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 96
    },
    {
      "id": "api/commands/filter#command-log",
      "doc_id": "api/commands/filter",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Filter the li's to the li with the class 'active'._**\n\n```\ncy.get('.left-nav>.nav').find('>li').filter('.active')\n```\n\nThe commands above display in the Command Log as:\n\nClicking the `filter` command in the Command Log outputs the following to the console:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 52
    },
    {
      "id": "api/commands/filter#history",
      "doc_id": "api/commands/filter",
      "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 `.filter()` 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) | `.filter()` is now a query. |\n| [3.2.0](/llm/markdown/app/references/changelog.md#3-2-0) | `.filter()` reads `options` when its first argument is a function. |\n| [3.0.0](/llm/markdown/app/references/changelog.md#3-0-0) | The type definition accepts a function argument. |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/filter.json",
      "token_estimate": 76
    }
  ]
}