Landing pull request 491. Fix #7322. Make .is() with a positional selector work like delegated event logic. Fixes #7322.

More Details:
 - https://github.com/jquery/jquery/pull/491
 - http://bugs.jquery.com/ticket/7322
This commit is contained in:
Dave Methvin
2011-09-19 23:50:52 -04:00
committed by timmywil
parent 2e5522a406
commit 70e2e32e0e
2 changed files with 48 additions and 3 deletions

View File

@@ -73,9 +73,14 @@ jQuery.fn.extend({
},
is: function( selector ) {
return !!selector && ( typeof selector === "string" ?
jQuery.filter( selector, this ).length > 0 :
this.filter( selector ).length > 0 );
return !!selector && (
typeof selector === "string" ?
// If this is a positional selector, check membership in the returned set
// so $("p:first").is("p:last") won't return true for a doc with two "p".
POS.test( selector ) ?
jQuery( selector, this.context ).index( this[0] ) >= 0 :
jQuery.filter( selector, this ).length > 0 :
this.filter( selector ).length > 0 );
},
closest: function( selectors, context ) {