Bug Tracker

Ticket #6912 (closed bug: fixed)

Opened 4 years ago

Last modified 3 years ago

$().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:
Blocking: Blocked by:

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

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

Change History

Changed 4 years ago by dmethvin

comment:1 Changed 4 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 4 years ago by snover

  • Priority set to low
  • Status changed from new to open
  • Version changed from 1.4.2 to 1.4.3
  • Milestone 1.4.3 deleted

comment:3 Changed 4 years ago by john

  • Owner set to john
  • Status changed from open to assigned
  • Milestone set to 1.6

comment:4 Changed 4 years ago by John Resig

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: 728a70c036dfcdc0c45c5c60c08aeade786ce195

comment:5 Changed 3 years ago by timmywil

#6867 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.