Element.closest
toastal opened this issue · 2 comments
toastal commented
Prerequisites
- Before opening an issue, please check the DOM standard (https://dom.spec.whatwg.org/). If it doesn't appear in this spec, it may be present in the spec for one of the other
purescript-webprojects. Although MDN is a great resource, it is not a suitable reference for this project.
https://dom.spec.whatwg.org/#dom-element-closest
Description
There's querySelector and querySelectorAll, but not closest despite good browser support.
JordanMartinez commented
Thought I'd include this link: Can I Use - 'Element.closest'
toastal commented
The polyfills if needed
if (!Element.prototype.matches) {
Element.prototype.matches =
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
}
if (!Element.prototype.closest) {
Element.prototype.closest = function(s) {
var el = this;
do {
if (Element.prototype.matches.call(el, s)) return el;
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
};
}