Skip to main content

Bug Tracker

Side navigation

#8253 closed bug (wontfix)

Opened February 11, 2011 11:11PM UTC

Closed March 31, 2011 12:50AM UTC

Selectors documentation says names must be double backslash-encoded

Reported by: Chealer Owned by:
Priority: low Milestone: 1.next
Component: selector Version: 1.5
Keywords: Cc: kswedberg
Blocked by: Blocking:
Description

http://api.jquery.com/category/selectors/ says:

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 an element with id="foo.bar", you can use the selector $("#foo\\\\.bar").

Of course, the selector needs a single backslash for escaping. The paragraph is confused because in JavaScript, backslashes also escape string literals, and selectors are usually built from JavaScript string literals. To use the same example, if you have an element with id="foo.bar", you should use the selector "#foo\\.bar", but that selector is written "#foo\\\\.bar" in JavaScript.

The nuance can be tricky, and PHP folks, who have a similar situation with regular expressions, put an explaining note, as can be seen on http://ca.php.net/manual/en/regexp.reference.escape.php

It's quite important to have that note; a simple fix without a similar note would probably be as confusing as the current paragraph is incorrect.

You'll also note that the text contains a double "an" ("an an element").

Attachments (0)
Change History (2)

Changed February 12, 2011 12:17AM UTC by jitter comment:1

cc: → kswedberg
component: unfiledselector
priority: undecidedlow
status: newopen

I don't know, I could imagine adding this note to cause more confusion but it's surely worth a consideration. Bringing in our documentation folks on this one.

Changed March 31, 2011 12:50AM UTC by addyosmani comment:2

resolution: → wontfix
status: openclosed

After careful consideration, in my opinion adding this note would increase confusion, particularly amongst those who aren't as familiar with the nuances of JavaScript string literals (on one hand, we're already trying to get across the idea that two backslashes are needed for meta-characters, do we really need to add another thing for beginners to understand which they may not use in the same note?).

I did write out a version with Chealer's changes in there, but again..I can't see this adding as much value as it would confusion (with beginners in mind).

The 'an an' change has however been made. If kswedberg has a different opinion on this and feels that we should reopen and update to include a note, I'll totally respect that.