Skip to main content

Bug Tracker

Side navigation

#8861 closed bug (worksforme)

Opened April 13, 2011 02:38PM UTC

Closed April 16, 2011 05:42PM UTC

Selectors not evaluating integer variables correctly

Reported by: Tom English <tomrenglish@googlemail.com> Owned by: Tom English <tomrenglish@googlemail.com>
Priority: undecided Milestone: 1.next
Component: selector Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:
Description

When using the jquery selector like so:

$('input[name="product[id]"][value="' + product_id + '"]')

Where the variable product_id is equal to an integer, jquery returns incorrect matches. If product_id is in the range 10-19 then it will match to inputs with the value of 1, if it is 20-29 it will match 2 and so on.

To get jQuery to select the correct objects I did the following:

var selector = 'input[name="product[id]"][value="' + product_id + '"]';
$(selector);

I think that the problem lies in the order/way that jquery is evaluating the arguments of the selector.

Tom

Attachments (0)
Change History (2)

Changed April 13, 2011 02:44PM UTC by timmywil comment:1

component: unfiledselector
owner: → Tom English <tomrenglish@googlemail.com>
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsFiddle.net that reproduces the issue experienced to help us assess your ticket.

Additionally, test against the jQuery (edge) version to ensure the issue still exists.

Changed April 16, 2011 05:42PM UTC by addyosmani comment:2

resolution: → worksforme
status: pendingclosed

I've reproduced your test case here: http://jsfiddle.net/addyosmani/mFYSP/ and just in case you're not actually passing the id directly to your first selector and mean 'id' literally, I've also tested here: http://jsfiddle.net/PbfG9/1/. Both of these work fine in Firefox and Webkit based browsers without any issue. This also works fine in IE6. Closing ticket.