Added support for the new .closest() method (very useful for event delegation).
This commit is contained in:
parent
c9dd5d9972
commit
6b09032864
2 changed files with 19 additions and 0 deletions
11
src/core.js
11
src/core.js
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue