Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#6867 closed bug (duplicate)

jQuery.fn.add adds incorrect elements when given select or form DOM nodes

Reported by: scott_h Owned by:
Priority: low Milestone: 1.next
Component: traversing Version: 1.4.2
Keywords: add, makeArray Cc:
Blocked by: Blocking:


Some DOM elements have a length property -- e.g., select box elements and forms, which alias their options and elements collections respectively -- and these cause jQuery.makeArray to consider them as arrays rather than array items. This has the effect that jQuery().add(mySelectElement) returns a list of option elements instead of a single select element.

Attachments (2)

test-jQuery.fn.add-with-select-or-form-element.html (1.3 KB) - added by scott_h 13 years ago.
test-jQuery.fn.add-with-select-or-form-element.2.html (1.3 KB) - added by scott_h 13 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 13 years ago by scott_h

This affects Chrome, Safari, Firefox, IE7 and IE8 (Opera untested).

comment:2 Changed 13 years ago by scott_h

Fixed test - the first one is incorrect, so please use the second one.

comment:4 Changed 13 years ago by dmethvin

I agree with this patch, but there is a test case that fails when it is applied (Pass makeArray a form (treat as elements)) that indicates it is intended. The api docs don't specifically mention this behavior as a feature, though. Also, the one place I could think of where it might be depended upon, serializeArray, already checks for form.elements so it doesn't need makeArray to do this AFAICT.

comment:5 Changed 13 years ago by SlexAxton

Priority: low
Status: newopen

comment:6 Changed 12 years ago by scott_h

This is fixed in v1.6, duplicates #6912.

comment:7 Changed 12 years ago by Timmy Willison

Component: coretraversing
Resolution: duplicate
Status: openclosed

Thank you scott_h! You're right.

comment:8 Changed 12 years ago by Timmy Willison

Duplicate of #6912.

Note: See TracTickets for help on using tickets.