Skip to content
Permalink
Browse files

Fix #11543: .has should work on detached elements.

  • Loading branch information...
gibson042 authored and dmethvin committed Apr 2, 2012
1 parent c04bfce commit 590bcab245d969dffc3c61b7679ab4d1a9a26ebd
Showing with 13 additions and 4 deletions.
  1. +1 −1 src/traversing.js
  2. +12 −3 test/unit/traversing.js
@@ -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] ) ) {
@@ -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" );

0 comments on commit 590bcab

Please sign in to comment.
You can’t perform that action at this time.