Bug Tracker

Modify

Ticket #6867 (closed bug: duplicate)

Opened 3 years ago

Last modified 2 years ago

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

Changed 3 years ago by scott_h

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

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

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

comment:6 Changed 2 years ago by scott_h

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

comment:7 Changed 2 years ago by timmywil

  • Status changed from open to closed
  • Resolution set to duplicate
  • Component changed from core to traversing

Thank you scott_h! You're right.

comment:8 Changed 2 years ago by timmywil

Duplicate of #6912.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.