Commit 590bcab2 authored by Richard Gibson's avatar Richard Gibson Committed by Dave Methvin

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

parent c04bfce5
...@@ -54,7 +54,7 @@ jQuery.fn.extend({ ...@@ -54,7 +54,7 @@ jQuery.fn.extend({
}, },
has: function( target ) { has: function( target ) {
var targets = jQuery( target ); var targets = jQuery( target, this );
return this.filter(function() { return this.filter(function() {
for ( var i = 0, l = targets.length; i < l; i++ ) { for ( var i = 0, l = targets.length; i < l; i++ ) {
if ( jQuery.contains( this, targets[i] ) ) { if ( jQuery.contains( this, targets[i] ) ) {
......
...@@ -370,21 +370,27 @@ test("not(jQuery)", function() { ...@@ -370,21 +370,27 @@ test("not(jQuery)", function() {
}); });
test("has(Element)", function() { test("has(Element)", function() {
expect(2); expect(3);
var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]); var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" ); 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]); 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" ); deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
}); });
test("has(Selector)", function() { test("has(Selector)", function() {
expect(3); expect(4);
var obj = jQuery("#qunit-fixture").has("#sndp"); 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" ); 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"); 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" ); 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() { ...@@ -393,11 +399,14 @@ test("has(Selector)", function() {
}); });
test("has(Arrayish)", function() { test("has(Arrayish)", function() {
expect(3); expect(4);
var simple = jQuery("#qunit-fixture").has(jQuery("#sndp")); 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" ); 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")); 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" ); deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment