Skip to content
masterclass Buddy

Cypress · Method

cy.closest

Use cy.closest(selector) to find the nearest matching element or ancestor. It checks the subject first, then moves up the DOM tree.

Last updated

Since
12.0.0

Syntax

.closest(selector)
.closest(selector, options)

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • .first()
  • .parent()
  • .parents()
  • .parentsUntil()
  • .prev()
  • .prevAll()
  • .prevUntil()

Source: cy.closest() | Cypress API Documentation. Checked 2026-11-03.