Ticket #87 (closed bug: fixed)
$() bug!
| Reported by: | gilles@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.0 |
| Component: | core | Version: | 1.0a |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
See test case code @ http://www.webunity.nl/_test/jquery/formbug/
Change History
comment:2 Changed 7 years ago by dave.methvin
The problem seems to be here in the jQuery constructor:
// Watch for when an array is passed in this.get( a.constructor == Array || a.length && a[0] != undefined && a[0].nodeType ?
The select element has a length property, it has a "0" property (the first option), and the first option naturally has a nodeType. However, it isn't an array so it should go to the non-array case. Ugh.
comment:3 Changed 7 years ago by Gilles
Reverting to 110 code seems to fix the problem:
// Watch for when an array is passed in this.get( a.constructor == Array ?
instead of:
// Watch for when an array is passed in this.get( a.constructor == Array || a.length && a[0] != undefined && a[0].nodeType ?
It's pretty logical, since when it is an array, all other checks are true. I have even tested submitting multiple checkboxes with thesame name ( name="items[]" ) and serializing of this also still works.
comment:4 Changed 7 years ago by john
- Status changed from new to closed
- Resolution set to fixed
Resolved in SVN. I added an additional nodeType check to make sure that 'a' was, in fact, not a node.
I really really want to be able to pass in an array of elements (including non-standard arrays) to jQuery. Essentially, it's all for this:
$( form.elements )
Greatest browser feature ever.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

This seems to be the same problem, but another testcase: http://fuzz.bassistance.de/jQueryFormValidation/selectBug.html
For a simple select element: <select id="select1">
</select>
var selectElement = $("#select1").get(0); both outputs should be the same console.debug($("#select1")); console.debug($(selectElement)); actually, the first contains the select, but the second contains the three options
Console output is this: [<select id="select1">] [<option value="1">,<option value="2">,<option value="3">]