Ticket #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: | |
| Blocking: | Blocked by: |
Description
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
Change History
comment:1 Changed 3 years ago by scott_h
This affects Chrome, Safari, Firefox, IE7 and IE8 (Opera untested).
Changed 3 years ago by scott_h
-
attachment
test-jQuery.fn.add-with-select-or-form-element.2.html
added
comment:2 Changed 3 years ago by scott_h
Fixed test - the first one is incorrect, so please use the second one.
comment:3 Changed 3 years ago by scott_h
Here's the fix I propose for this bug:
http://github.com/shghs/jquery/commit/904ef97ed1175b6f899efe9240381c8b0638667d
comment:4 Changed 3 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 3 years ago by SlexAxton
- Priority set to low
- Status changed from new to open
- Milestone changed from 1.4.3 to 1.4.5
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
