Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save illvart/6dbfc9a8215575d1158db1a0b4ce3d4c to your computer and use it in GitHub Desktop.
Save illvart/6dbfc9a8215575d1158db1a0b4ce3d4c to your computer and use it in GitHub Desktop.
matchesSelector Polyfill // returns whether an element matches a selector
this.Element && function(ElementPrototype) {
ElementPrototype.matchesSelector = ElementPrototype.matchesSelector ||
ElementPrototype.mozMatchesSelector ||
ElementPrototype.msMatchesSelector ||
ElementPrototype.oMatchesSelector ||
ElementPrototype.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);
this.Element&&function(e){e.matchesSelector=e.matchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector||function(e){var t=this,n=(t.parentNode||t.document).querySelectorAll(e),r=-1;while(n[++r]&&n[r]!=t);return!!n[r]}}(Element.prototype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment