findClosest.js 293 B

1234567891011121314
  1. 'use strict';
  2. function findClosest(element, callback) {
  3. let el = element;
  4. do {
  5. if (callback(el)) {
  6. return el;
  7. }
  8. el = el.parentElement;
  9. }while (el && el !== element.ownerDocument.body)
  10. return undefined;
  11. }
  12. exports.findClosest = findClosest;