Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created July 6, 2012 21:51
Show Gist options
  • 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)
@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