aboutsummaryrefslogtreecommitdiffstats
path: root/src/traversing.js
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2011-09-19 23:50:52 -0400
committertimmywil <timmywillisn@gmail.com>2011-09-19 23:50:52 -0400
commit70e2e32e0eb03607ad0c8b7752dbd7747da47164 (patch)
treea48bb145515cfe6bb5f5635fe1aa4db900aba8b1 /src/traversing.js
parent2e5522a406de493f85832ed1adb57c0f4ce87a9c (diff)
downloadjquery-70e2e32e0eb03607ad0c8b7752dbd7747da47164.tar.gz
jquery-70e2e32e0eb03607ad0c8b7752dbd7747da47164.zip
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
Diffstat (limited to 'src/traversing.js')
-rw-r--r--src/traversing.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/traversing.js b/src/traversing.js
index 35a5174e9..fa9462216 100644
--- a/src/traversing.js
+++ b/src/traversing.js
@@ -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 ) {