Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Traversing: Check all pairwise element combinations for .find( els )

Ref b8d0d54
Fixes #14701
  • Loading branch information...
commit 391c21b15d769fac1c37631b28c0226f57a59796 1 parent a2250b0
Richard Gibson gibson042 authored
Showing with 7 additions and 6 deletions.
  1. +3 −4 src/traversing/findFilter.js
  2. +4 −2 test/unit/traversing.js
7 src/traversing/findFilter.js
View
@@ -53,14 +53,14 @@ jQuery.filter = function( expr, elems, not ) {
jQuery.fn.extend({
find: function( selector ) {
- var i = 0,
+ var i,
len = this.length,
ret = [],
self = this;
if ( typeof selector !== "string" ) {
return this.pushStack( jQuery( selector ).filter(function() {
- for ( ; i < len; i++ ) {
+ for ( i = 0; i < len; i++ ) {
if ( jQuery.contains( self[ i ], this ) ) {
return true;
}
@@ -68,8 +68,7 @@ jQuery.fn.extend({
}) );
}
- i = 0;
- for ( ; i < len; i++ ) {
+ for ( i = 0; i < len; i++ ) {
jQuery.find( selector, self[ i ], ret );
}
6 test/unit/traversing.js
View
@@ -24,19 +24,21 @@ test( "find(leading combinator)", function() {
});
test( "find(node|jQuery object)", function() {
- expect( 12 );
+ expect( 13 );
var $foo = jQuery("#foo"),
$blog = jQuery(".blogTest"),
$first = jQuery("#first"),
$two = $blog.add( $first ),
+ $twoMore = jQuery("#ap").add( $blog ),
$fooTwo = $foo.add( $blog );
equal( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" );
equal( $foo.find( $blog[ 0 ] ).text(), "Yahoo", "Find with blog node" );
equal( $foo.find( $first ).length, 0, "#first is not in #foo" );
equal( $foo.find( $first[ 0 ]).length, 0, "#first not in #foo (node)" );
- ok( $foo.find( $two ).is(".blogTest"), "Find returns only nodes within #foo" );
+ deepEqual( $foo.find( $two ).get(), $blog.get(), "Find returns only nodes within #foo" );
+ deepEqual( $foo.find( $twoMore ).get(), $blog.get(), "...regardless of order" );
ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" );
ok( $fooTwo.find( $blog[ 0 ] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" );
Please sign in to comment.
Something went wrong with that request. Please try again.