Skip to main content

Bug Tracker

Side navigation

#6867 closed bug (duplicate)

Opened August 04, 2010 03:59AM UTC

Closed May 04, 2011 02:11PM UTC

Last modified May 04, 2011 02:11PM UTC

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 (8)

Changed August 04, 2010 04:04AM UTC by scott_h comment:1

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

Changed August 04, 2010 04:20AM UTC by scott_h comment:2

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

Changed August 04, 2010 10:56AM UTC by scott_h comment:3

Changed August 21, 2010 02:25PM UTC by dmethvin comment:4

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.

Changed October 23, 2010 11:49PM UTC by SlexAxton comment:5

milestone: 1.4.31.4.5
priority: → low
status: newopen

Changed May 04, 2011 05:45AM UTC by scott_h comment:6

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

Changed May 04, 2011 02:11PM UTC by timmywil comment:7

component: coretraversing
resolution: → duplicate
status: openclosed

Thank you scott_h! You're right.

Changed May 04, 2011 02:11PM UTC by timmywil comment:8

Duplicate of #6912.