Created
November 7, 2012 09:51
-
-
Save ralt/4030481 to your computer and use it in GitHub Desktop.
Closest() rewritten
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
if (!Node.prototype.matchesSelector) { | |
Node.prototype.matchesSelector = function(selector) { | |
return this === document.querySelector(selector); | |
}; | |
} | |
function closest(selector, el) { | |
if (el.parentNode.matchesSelector(selector)) { | |
return el.parentNode; | |
} | |
else { | |
// No TCO, but heh... | |
return closest(selector, el.parentNode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment