Skip to content

Commit

Permalink
Make sure that forms and selects are added to a jQuery set correctly.…
Browse files Browse the repository at this point in the history
… Fixes #6912.
  • Loading branch information
jeresig committed Apr 17, 2011
1 parent a9b81d7 commit 728a70c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) ?
Expand Down
5 changes: 3 additions & 2 deletions test/unit/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -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)" );

This comment has been minimized.

Copy link
@dmethvin

dmethvin Apr 17, 2011

Member

Yay! I always thought this was strange.

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() {
Expand Down

0 comments on commit 728a70c

Please sign in to comment.