]> source.dussan.org Git - jquery.git/commitdiff
Fix #11543: .has should work on detached elements.
authorRichard Gibson <richard.gibson@gmail.com>
Mon, 2 Apr 2012 17:12:57 +0000 (13:12 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Fri, 6 Apr 2012 01:03:41 +0000 (21:03 -0400)
src/traversing.js
test/unit/traversing.js

index 08c95ec4ab6824877b3cb21c73a1cef8be55a238..2e45aade7ab6e157e9c05250ef0d4dd7d46842b6 100644 (file)
@@ -54,7 +54,7 @@ jQuery.fn.extend({
        },
 
        has: function( target ) {
-               var targets = jQuery( target );
+               var targets = jQuery( target, this );
                return this.filter(function() {
                        for ( var i = 0, l = targets.length; i < l; i++ ) {
                                if ( jQuery.contains( this, targets[i] ) ) {
index 8e8b5360ae55a49dc9560ab20a6a362cef0a0164..80d30aa19bd38acd8f02fc87cf76bfb10a9d8b49 100644 (file)
@@ -370,21 +370,27 @@ test("not(jQuery)", function() {
 });
 
 test("has(Element)", function() {
-       expect(2);
+       expect(3);
 
        var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
        deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
 
+       var detached = jQuery("<a><b><i/></b></a>");
+       deepEqual( detached.has( detached.find("i")[0] ).get(), detached.get(), "...Even when detached" );
+
        var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
        deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
 });
 
 test("has(Selector)", function() {
-       expect(3);
+       expect(4);
 
        var obj = jQuery("#qunit-fixture").has("#sndp");
        deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
 
+       var detached = jQuery("<a><b><i/></b></a>");
+       deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
+
        var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
        deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
 
@@ -393,11 +399,14 @@ test("has(Selector)", function() {
 });
 
 test("has(Arrayish)", function() {
-       expect(3);
+       expect(4);
 
        var simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
        deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
 
+       var detached = jQuery("<a><b><i/></b></a>");
+       deepEqual( detached.has( detached.find("i") ).get(), detached.get(), "...Even when detached" );
+
        var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
        deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );