randomMDNrandomMDN
Aug 20, 2026, 10:05 AM🦖 Element: closest() method
✅ Widely available (from Apr 2017)
https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
The closest() method of the Element interface traverses the element and its parents (heading toward the document root) until it finds a node that matches the specified CSS selector.