Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created July 6, 2012 21:51
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save jonathantneal/3062955 to your computer and use it in GitHub Desktop.
Save jonathantneal/3062955 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)
@sounisi5011
Copy link

What are the license of this code?

@holloway
Copy link

Yes, is this free to use?

@asolove
Copy link

asolove commented Oct 19, 2016

For those who need this code and don't know its license, there is a free-to-use polyfill with the same effect on MDN: https://developer.mozilla.org/en-US/docs/Web/API/Element/matches

@sunnyknarayan
Copy link

can someone tell where to write this code like in polyfill.ts under all imports or anywhere else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment