Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
var vendor = Element.prototype.matches || Element.prototype.msMatchesSelector
function matches (el, selector) {
if (!el || el.nodeType !== 1) return false;
if (vendor) return, selector);
return false;
function closest (element, selector) {
var parent = element
while (parent && parent !== document) {
if (matches(parent, selector)) return parent;
parent = parent.parentNode
document.addEventListener('click', function (event) {
console.log(matches(, '.add-to-cart .btn-cart'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment