Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#6912 closed bug (fixed)

$().add(selectElement) adds option children instead

Reported by: ratbeard Owned by: john
Priority: low Milestone: 1.6
Component: traversing Version: 1.4.3
Keywords: Cc:
Blocked by: Blocking:

Description

Passing a raw dom select element to jQuery.fn.add adds all of its option children to the collection, instead of the select element itself.

Array.prototype.slice.call() inside makeArray gets confused probably due to the select element having a length property.

Tested this in Chrome 5 and FF 3.6 on osx 10.6.

Workaround is to wrap the select element in jQuery()

Attachments (1)

test-6912.html (645 bytes) - added by dmethvin 13 years ago.

Download all attachments as: .zip

Change History (6)

Changed 13 years ago by dmethvin

Attachment: test-6912.html added

comment:1 Changed 13 years ago by dmethvin

There is a similar situation with form elements but it seems to be by intent because there is a test case to verify that adding a form actually adds the form.elements collection.

It seems that .add("form#mine") should do the same thing as .add(getElementById("mine")), and the same goes for select.

If that was the case, it might be easiest to fix this issue in makeArray by not turning DOMElement with .length into an array of its children.

comment:2 Changed 12 years ago by snover

Milestone: 1.4.3
Priority: low
Status: newopen
Version: 1.4.21.4.3

comment:3 Changed 12 years ago by john

Milestone: 1.6
Owner: set to john
Status: openassigned

comment:4 Changed 12 years ago by John Resig

Resolution: fixed
Status: assignedclosed

Make sure that forms and selects are added to a jQuery set correctly. Fixes #6912.

Changeset: 728a70c036dfcdc0c45c5c60c08aeade786ce195

comment:5 Changed 12 years ago by timmywil

#6867 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.