Quantcast
Channel: Elly Loel
Viewing all articles
Browse latest Browse all 439

Element.closest()

$
0
0
Element: closest() method - Web APIs | MDN

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.

If you’re trying to do a :has() style check to see if an element has a certain parent, then Element.closest() is what you need. Don’t bother with looping through parent nodes, like I almost did :joy:


Viewing all articles
Browse latest Browse all 439

Trending Articles