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.
closest()
MDN Reference
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.MDN Reference