Bug Tracker

Opened 15 years ago

Closed 15 years ago

#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:
Blocked by: Blocking:


At least it won't using Firefox (tested in 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:


(change is in backslashes escaping . near the end of the expression)

Change History (3)

comment:1 in reply to:  description Changed 15 years ago by derek

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.

comment:2 Changed 15 years ago by davidserduke

Good idea. It's now in the faq.

comment:3 Changed 15 years ago by brandon

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.