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.
SubscribeRelated
.first().parent().parents().parentsUntil().prev().prevAll().prevUntil()