#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: |
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 (2)
Change History (10)
Changed 13 years ago by
Attachment: | test-jQuery.fn.add-with-select-or-form-element.html added |
---|
comment:1 Changed 13 years ago by
Changed 13 years ago by
Attachment: | test-jQuery.fn.add-with-select-or-form-element.2.html added |
---|
comment:2 Changed 13 years ago by
Fixed test - the first one is incorrect, so please use the second one.
comment:3 Changed 13 years ago by
Here's the fix I propose for this bug:
http://github.com/shghs/jquery/commit/904ef97ed1175b6f899efe9240381c8b0638667d
comment:4 Changed 13 years ago by
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
Milestone: | 1.4.3 → 1.4.5 |
---|---|
Priority: | → low |
Status: | new → open |
comment:7 Changed 12 years ago by
Component: | core → traversing |
---|---|
Resolution: | → duplicate |
Status: | open → closed |
Thank you scott_h! You're right.
This affects Chrome, Safari, Firefox, IE7 and IE8 (Opera untested).