Bug Tracker

Ticket #10862 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

Sytax bug

Reported by: lakhtionov@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:


jQuery has a problem dealing with the "+" character.


<input id="hello+2" value="wagon" />

alert($('#hello+2').val()); displays: undefined

alert(document.getElementById('hello+2').value); displays: wagon

Change History

comment:1 Changed 4 years ago by ajpiano

  • Status changed from new to closed
  • Resolution set to invalid

Thanks for taking a moment to try to help the jQuery project, but this is not a valid bug. + is a selector (for adjacent siblings). As is stated in the selectors docs ( http://api.jquery.com/category/selectors/):

If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]`{|}~ ) as a literal part of a name, you must escape the character with two backslashes:
. For example, if you have an element with id="foo.bar", you can use the selector $("#foo
.bar"). The W3C CSS specification contains the complete set of rules regarding valid CSS selectors.

It works fine once you do the escaping:  http://jsfiddle.net/xvk3Z/

In the future please provide a test case and search the documentation before filing a bug.

Note: See TracTickets for help on using tickets.