Skip to content

Instantly share code, notes, and snippets.

@rhysburnie
Last active November 28, 2024 00:49
Show Gist options
  • Select an option

  • Save rhysburnie/8fc4b80a8d546a650c97 to your computer and use it in GitHub Desktop.

Select an option

Save rhysburnie/8fc4b80a8d546a650c97 to your computer and use it in GitHub Desktop.
Polyfill Element.matches
if(typeof window!=="undefined"){
window.Element && function(proto) {
if(!proto.matches) {
proto.matches = proto.matchesSelector ||
proto.mozMatchesSelector ||
proto.msMatchesSelector ||
proto.oMatchesSelector ||
proto.webkitMatchesSelector ||
function (selector) {
var node = this, nodes = (node.parentNode || node.document).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