admin管理员组文章数量:1390464
I'm using svelte+rollup+rollup-plugin-polyfill
SCRIPT438: Object doesn't support property or method 'closest'
still occurs even though I include
polyfill(['@webponents/webponentsjs','element-closest']),
in my rollup.js.
the call occurs in this code:
function onDocumentClick (e) {
if (!e.target.closest('.autoplete')) close();
}
why the polyfill does not exist? and though, how to correctly use it? I'm thinking of just replacing .closest with one IE11 supports.
I'm using svelte+rollup+rollup-plugin-polyfill
SCRIPT438: Object doesn't support property or method 'closest'
still occurs even though I include
polyfill(['@webponents/webponentsjs','element-closest']),
in my rollup.js.
the call occurs in this code:
function onDocumentClick (e) {
if (!e.target.closest('.autoplete')) close();
}
why the polyfill does not exist? and though, how to correctly use it? I'm thinking of just replacing .closest with one IE11 supports.
Share asked Dec 23, 2019 at 12:09 KampaiiKampaii 3013 silver badges15 bronze badges 1-
1
The
.closest()
method of the DOM traversal has nothing to do with Web Components, that's why it will unlikely be found in any suite of Web Components polyfills. However, you can quite easily polyfill it manually, e.g. with one of the methods provided by MDN: developer.mozilla/en-US/docs/Web/API/Element/… – Ilya Streltsyn Commented Dec 23, 2019 at 12:33
1 Answer
Reset to default 6Use Polyfill
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;
};
}
Closest in detail and Polyfill
本文标签: javascriptHow to support closest in IE11Stack Overflow
版权声明:本文标题:javascript - How to support .closest in IE11 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744649489a2617598.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论