findClosest.js 267 B

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