Bug Tracker

Modify

Ticket #8861 (closed bug: worksforme)

Opened 2 years ago

Last modified 2 years ago

Selectors not evaluating integer variables correctly

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

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

Change History

comment:1 Changed 2 years ago by timmywil

  • Owner set to Tom English <tomrenglish@…>
  • Status changed from new to pending
  • Component changed from unfiled to selector

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.

comment:2 Changed 2 years ago by addyosmani

  • Status changed from pending to closed
  • Resolution set to worksforme

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.

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.