istesequi
Version:
Lightweight and intuitive javascript library
20 lines (16 loc) • 387 B
JavaScript
/**
* .closest()
*
* Find a node that matches the passed selector
* @return this Umbrella object
*/
u.prototype.closest = function(selector) {
return this.join(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)
});
};