[펌글] jQuery 특수문자 (special character) 목록

By | 11월 23, 2011
- 출처 : http://www.xinotes.org/notes/note/958/ -

The jQuery doc 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: \\. 

So what are these meta-characters? According to the CSS specification: 
In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); 

These meta-characters are the printable characters in the ASCII but outside the range allowed by CSS identifiers. They must be escaped, with two backslashes. Why two backslashes? Because one backslash is consumed by JavaScript, and with only one backslash in place, no backslash is passed to jQuery after JavaScript escapes it. 

Plus, some of the meta-characters are used by jQuery itself with special meanings: 
 

Character Meaning
# id selector
, multiple selector, e.g., $('class1, class2')
. the dot, class selector
+ next adjacent selector: "prev + next"
* all selector $('*'), attribute contains selector [name*='value']
~ attribute contains word selector [name~='value']; next siblings selector 'prev ~ siblings'
'" * double quotes inside single quotes: $('a[rel="nofollow self"]') 
* single quotes inside double quotes: $("a[rel='nofollow self']") 
* escaped single quotes inside single quotes: $('a[rel=\'nofollow self\']') 
* escaped double quotes inside double quotes: $("a[rel=\"nofollow self\"]") 
: special attribute selector, e.g., :visible:button:checked:first
] attributes selector
! negative: [name!='value']
^ attribute starts with: [name^='value']
$ attribute ends with: [name$='value']
| attribute contains prefix selector: [name|='value']
() used in function, :eq()
= equality operator
> child selector: parent > child
@ used as attribute selector prior to 1.3

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments