closest.js 466 B

12345678910111213141516171819
  1. // https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
  2. if (!Element.prototype.matches) {
  3. Element.prototype.matches
  4. = Element.prototype.msMatchesSelector
  5. || Element.prototype.webkitMatchesSelector
  6. }
  7. if (!Element.prototype.closest) {
  8. Element.prototype.closest = function(s) {
  9. var el = this
  10. do {
  11. if (el.matches(s)) return el
  12. el = el.parentElement || el.parentNode
  13. } while (el !== null && el.nodeType === 1)
  14. return null
  15. }
  16. }