UNPKG

@kickscondor/umbrellajs

Version:

Lightweight and intuitive javascript library

12 lines (11 loc) 360 B
// Find the first ancestor that matches the selector for each node u.prototype.closest = function (selector) { return this.map(function (node) { // Keep going up and up on the tree. First element is also checked do { if (u(node).is(selector)) { return node; } } while ((node = node.parentNode) && node !== document); }); };