From: John Resig Date: Sun, 17 Apr 2011 17:51:24 +0000 (-0700) Subject: Make sure that forms and selects are added to a jQuery set correctly. Fixes #6912. X-Git-Tag: 1.6rc1~11^2~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=728a70c036dfcdc0c45c5c60c08aeade786ce195;p=jquery.git Make sure that forms and selects are added to a jQuery set correctly. Fixes #6912. --- diff --git a/src/traversing.js b/src/traversing.js index e0f40151d..8c4b4ef83 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -160,7 +160,7 @@ jQuery.fn.extend({ add: function( selector, context ) { var set = typeof selector === "string" ? jQuery( selector, context ) : - jQuery.makeArray( selector ), + jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ), all = jQuery.merge( this.get(), set ); return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ? diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 109a9aa6d..7e1ee6ff0 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -480,7 +480,7 @@ test("contents()", function() { }); test("add(String|Element|Array|undefined)", function() { - expect(16); + expect(17); same( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); same( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" ); ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" ); @@ -519,7 +519,8 @@ test("add(String|Element|Array|undefined)", function() { var notDefined; equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" ); - ok( jQuery([]).add( document.getElementById("form") ).length >= 13, "Add a form (adds the elements)" ); + equals( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" ); + equals( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" ); }); test("add(String, Context)", function() {