Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix a regression where has with multiple contexts was not filtering c…

…orrectly. Test added.
  • Loading branch information...
commit e07b444dfe87f26f0d6031920026142425505ad6 1 parent 4039d36
Timmy Willison authored

Showing 2 changed files with 8 additions and 5 deletions. Show diff stats Hide diff stats

  1. +3 3 src/traversing.js
  2. +5 2 test/unit/traversing.js
6 src/traversing.js
@@ -48,12 +48,12 @@ jQuery.fn.extend({
48 48 },
49 49
50 50 has: function( target ) {
51   - var i = 0,
  51 + var i,
52 52 targets = jQuery( target, this ),
53   - l = targets.length;
  53 + len = targets.length;
54 54
55 55 return this.filter(function() {
56   - for ( ; i < l; i++ ) {
  56 + for ( i = 0; i < len; i++ ) {
57 57 if ( jQuery.contains( this, targets[i] ) ) {
58 58 return true;
59 59 }
7 test/unit/traversing.js
@@ -376,7 +376,7 @@ test("has(Element)", function() {
376 376 });
377 377
378 378 test("has(Selector)", function() {
379   - expect(4);
  379 + expect( 5 );
380 380
381 381 var obj = jQuery("#qunit-fixture").has("#sndp");
382 382 deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
@@ -385,7 +385,10 @@ test("has(Selector)", function() {
385 385 deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
386 386
387 387 var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
388   - deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
  388 + deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
  389 +
  390 + multipleParent = jQuery("#select1, #select2, #select3").has("#option1a, #option3a");
  391 + deepEqual( multipleParent.get(), q("select1", "select3"), "Multiple contexts are checks correctly" );
389 392
390 393 var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
391 394 deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );

0 comments on commit e07b444

Please sign in to comment.
Something went wrong with that request. Please try again.