Vanilla JavaScript .closest without jQuery

Modern browsers have the Element.closest() method.

Example:

document.querySelector('.navPanel img').closest('td')

Reference:
https://developer.mozilla.org/en-US/docs/Web/API/Element/closest

Here you can check which browsers have built-in support:
https://caniuse.com/#feat=element-closest

When there is no support in the browser the following polyfill could be used:
https://github.com/jonathantneal/closest

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)