Skip to main content

Bug Tracker

Side navigation

#1895 closed bug (worksforme)

Opened November 06, 2007 04:47PM UTC

Closed November 14, 2007 04:42AM UTC

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:
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)

Attachments (0)
Change History (3)

Changed November 07, 2007 09:38AM UTC by derek comment:1

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.

Changed November 07, 2007 02:04PM UTC by davidserduke comment:2

Good idea. It's now in the faq.

Changed November 14, 2007 04:42AM UTC by brandon comment:3

resolution: → worksforme
status: newclosed