Skip to content
Permalink
Browse files

Store last closer value to jQuery.lastCloser instead of using data API.

  • Loading branch information
rkatic authored and jeresig committed Nov 7, 2009
1 parent 3106039 commit 0f03c7489fc2a8a3d806e13276cf61ae51ef641f
Showing with 5 additions and 4 deletions.
  1. +5 −4 src/traversing.js
@@ -52,19 +52,20 @@ jQuery.fn.extend({
},

closest: function( selector, context ) {
var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
closer = 0;
var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null;

return this.map(function(){
var cur = this;
var cur = this, closer = 0;
while ( cur && cur.ownerDocument && cur !== context ) {
if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
jQuery.data(cur, "closest", closer);
jQuery.lastCloser = closer;
return cur;
}
cur = cur.parentNode;
closer++;
}
jQuery.lastCloser = -1;
return null;
});
},

0 comments on commit 0f03c74

Please sign in to comment.
You can’t perform that action at this time.