Bug Tracker

Opened 12 years ago

Closed 12 years ago

#8253 closed bug (wontfix)

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:


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

If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;[email protected][\]`{|}~ ) 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

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").

Change History (2)

comment:1 Changed 12 years ago by jitter

Cc: kswedberg added
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.

comment:2 Changed 12 years ago by addyosmani

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.

Note: See TracTickets for help on using tickets.