13 lines
267 B
JavaScript
13 lines
267 B
JavaScript
function findClosest(element, callback) {
|
|
let el = element;
|
|
do {
|
|
if (callback(el)) {
|
|
return el;
|
|
}
|
|
el = el.parentElement;
|
|
}while (el && el !== element.ownerDocument.body)
|
|
return undefined;
|
|
}
|
|
|
|
export { findClosest };
|