Added support for the new .closest() method (very useful for event delegation).

This commit is contained in:
John Resig 2008-12-22 00:52:53 +00:00
parent c9dd5d9972
commit 6b09032864
2 changed files with 19 additions and 0 deletions

View file

@ -338,6 +338,17 @@ jQuery.fn = jQuery.prototype = {
}) ), "filter", selector );
},
closest: function( selector ) {
return this.map(function(){
var cur = this;
while ( cur && cur.ownerDocument ) {
if ( jQuery(cur).is(selector) )
return cur;
cur = cur.parentNode;
}
});
},
not: function( selector ) {
if ( typeof selector === "string" )
// test special case where just one selector is passed in