Skip to content

Commit bb6f577

Browse files
db6edrAurelioDeRosa
authored andcommitted
FAQ: Add = as a problematic character
HTML5 allows far more characters for the id attribute than does HTML4. Some of these now-valid characters lead to a syntax error when used with jQuery. The equals sign = is one of these. Closes jquerygh-716
1 parent 018aff8 commit bb6f577

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

page/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"title": "How do I select an element by an ID that has characters used in CSS notation?"
33
}</script>
44

5-
Because jQuery uses CSS syntax for selecting elements, some characters are interpreted as CSS notation. For example, ID attributes, after an initial letter (a-z or A-Z), may also use periods and colons, in addition to letters, numbers, hyphens, and underscores (see [W3C Basic HTML Data Types](http://www.w3.org/TR/html4/types.html#type-id)). The colon (":") and period (".") are problematic within the context of a jQuery selector because they indicate a pseudo-class and class, respectively.
5+
Because jQuery uses CSS syntax for selecting elements, some characters are interpreted as CSS notation. In order to tell jQuery to treat these characters literally rather than as CSS notation, they must be escaped by placing two backslashes in front of them.
66

7-
In order to tell jQuery to treat these characters literally rather than as CSS notation, they must be "escaped" by placing two backslashes in front of them.
7+
See the [Selector documentation](http://api.jquery.com/category/selectors/) for further details.
88

99
```
1010
// Does not work:
@@ -25,7 +25,7 @@ The following function takes care of escaping these characters and places a "#"
2525
```
2626
function jq( myid ) {
2727
28-
return "#" + myid.replace( /(:|\.|\[|\]|,)/g, "\\$1" );
28+
return "#" + myid.replace( /(:|\.|\[|\]|,|=)/g, "\\$1" );
2929
3030
}
3131
```

0 commit comments

Comments
 (0)