Created
June 26, 2016 06:34
-
-
Save ottonascarella/3ea0b0954d012cb0a492fb06459f0786 to your computer and use it in GitHub Desktop.
Polyfill matches DOM method (depends on querySelectorAll)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* improved version of the one found at https://developer.mozilla.org/docs/Web/API/Element/matches */ | |
(function(p) { | |
if (p.matches) return; | |
p.matches = | |
p.matchesSelector || | |
p.mozMatchesSelector || | |
p.msMatchesSelector || | |
p.oMatchesSelector || | |
p.webkitMatchesSelector || | |
function(s) { | |
var matches = (this.document || this.ownerDocument).querySelectorAll(s), | |
i = matches.length; | |
while (--i >= 0 && matches.item(i) !== this) { /* */ } | |
return i > -1; | |
}; | |
}(Element.prototype)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment