Bug Tracker

Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#87 closed bug (fixed)

$() bug!

Reported by: [email protected] Owned by:
Priority: undecided Milestone: 1.0
Component: core Version: 1.0a
Keywords: Cc:
Blocked by: Blocking:

Description

Change History (4)

comment:1 Changed 16 years ago by Jörn

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">

<option value="1">option1</option> <option value="2">option2</option> <option value="3">option3</option>

</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">]

comment:2 Changed 16 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 16 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 16 years ago by john

Resolution: fixed
Status: newclosed

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.

Note: See TracTickets for help on using tickets.