Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yuchuanxi/3add5e7bec8730e57fcd to your computer and use it in GitHub Desktop.
Save yuchuanxi/3add5e7bec8730e57fcd to your computer and use it in GitHub Desktop.
Element matches Polyfill
Element && !Element.prototype.matches && (function(proto) {
proto.matches = proto.matchesSelector ||
proto.mozMatchesSelector ||
proto.msMatchesSelector ||
proto.oMatchesSelector ||
proto.webkitMatchesSelector ||
function (selector) {
var node = this, nodes = (node.parentNode || node.document || element.ownerDocument)
.querySelectorAll(selector), i = -1;
while (nodes[ ++i ] && nodes[i] !== node);
return !!nodes[i];
};
})(Element.prototype);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment