Skip to content

Instantly share code, notes, and snippets.

@rayou
Created June 14, 2015 05:31
Show Gist options
  • Select an option

  • Save rayou/725b87dd8f6a382b06c2 to your computer and use it in GitHub Desktop.

Select an option

Save rayou/725b87dd8f6a382b06c2 to your computer and use it in GitHub Desktop.
matchesSelector.js
function matchesSelector(el, selector) {
var p = Element.prototype;
var f = p.matches || p.webkitMatchesSelector || p.mozMatchesSelector || p.msMatchesSelector || function(s) {
return [].indexOf.call(document.querySelectorAll(s), this) !== -1;
};
return f.call(el, selector);
}
// Usage
matchesSelector(document.getElementById('myDiv'), 'div.someSelector[some-attribute=true]')
//http://davidwalsh.name/essential-javascript-functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment