From d44e9451f789db40e7cb370717258c00dff10edd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Zaefferer?= Date: Thu, 6 Dec 2007 19:51:00 +0000 Subject: [PATCH] Fix for #2002 --- src/core.js | 2 +- test/unit/core.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core.js b/src/core.js index 23c1b79f3..be989ea9a 100644 --- a/src/core.js +++ b/src/core.js @@ -340,7 +340,7 @@ jQuery.fn = jQuery.prototype = { }, add: function( selector ) { - return this.pushStack( jQuery.merge( + return !selector ? this : this.pushStack( jQuery.merge( this.get(), selector.constructor == String ? jQuery( selector ).get() : diff --git a/test/unit/core.js b/test/unit/core.js index 5f2f81af8..bc1def389 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -208,8 +208,8 @@ test("get(Number)", function() { ok( $("p").get(0) == document.getElementById("firstp"), "Get A Single Element" ); }); -test("add(String|Element|Array)", function() { - expect(7); +test("add(String|Element|Array|undefined)", function() { + expect(8); isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" ); ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" ); @@ -221,6 +221,9 @@ test("add(String|Element|Array)", function() { var x = $([]).add("

xxx

").add("

xxx

"); ok( x[0].id == "x1", "Check on-the-fly element1" ); ok( x[1].id == "x2", "Check on-the-fly element2" ); + + var notDefined; + equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing." ); }); test("each(Function)", function() { -- 2.39.5