HTML DOM Element closest() Method
HTML DOM Element closest() Method
The closest() method is used to search up DOM tree for element that matches specific CSS selector. It starts at itself and then parent, grandparent, and so on until a match is found else it will return null.
Syntax:-
Its syntax is:- element.closest(selectors)
Return:-
Its return is:-closest ancestor element or element itself which matches a specific CSS selector
Further Explanation:-
Parameter | Description |
selectors | Required. One or more CSS selectors to match. |