Element.closest()

The DOM method that starts at an element and walks up through its ancestors, returning the first one, itself included, that matches a selector.

In more detail

It is the key to event delegation: from a click on an icon inside a button, closest('button.del') finds the button. It returns null when no ancestor matches.

Related terms

Taught in

References