Modify ↓
Ticket #1895 (closed bug: worksforme)
jquery not selecting by id where id contains a dot
| Reported by: | derek | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.2.2 |
| Component: | core | Version: | 1.2.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
At least it won't using Firefox (tested in 2.0.0.8) and earlier:
e.g. $("#error.password") won't find <span id="error.password">
Looks like the problem is in the regex used here (from /trunk/jquery/src/selector.js
2 var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
3 "(?:[\\w*_-]|\\\\.)" :
4 "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
5 quickChild = new RegExp("^>\\s*(" + chars + "+)"),
6 quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
7 quickClass = new RegExp("^([#.]?)(" + chars + "*)");
specifically line 4 would need to be like this to make it work:
"(?:[
w\u0128-\uFFFF*_-]|
.)"
(change is in backslashes escaping . near the end of the expression)
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

Sorry, ignore that, I was a bit hasty in thinking this was a bug.
Thanks to the forum I've learnt that jquery requires dots in selectors like this to be escaped, hence the
in the regex.
Turns out there is a FAQ entry about this ( http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_select_an_element_that_has_weird_characters_in_its_ID.3F).
Would be worth mentioning it in the API docs ( http://docs.jquery.com/Selectors/id#id) too though or putting a pointer to that FAQ there at least.