javascript - When do I need to escape metacharectars? (jQuery Selectors) -
according jquery docs, need escape metacharacters occur in selector strings, when occur literal. however, couldn't find many specific examples of when , when not escape selectors. when , when don't need escape metacharacters, when interpreted literal, in:
attribute selectors? ie
$("[attr=value]")
id selectors? ie
$("#id")
class selectors? ie
$(".class");
and, there way write function replaces metachars in selector strings, while still preserving beginning character? ie:
// replace meta chars, preserving id selection? $("#id.rest$of*string") // replace meta chars, preserving attribute selection? // going previous question, need escape metachars in situation? $("[attr=blah.dee#foo*yay]")
the reason ask question, because i'm working website happens have nasty selectors. , don't have control on website, can't go change selectors nicer work with.
thanks!!
from jquery docs:
if wish use of meta-characters (#;&,.+*~':"!^$=>|/ ) as literal part of name, must escape character 2 backslashes ...
all of these must escaped:
- id
- class name
- attribute name
- attribute value
- element name
the first 4 obvious, , here's example fifth. element names in xml can contain "." character instance , still valid.
<user.name>john doe</user.name>
if had select elements of user.name
, .
must escaped
$(xml).find("user\\.name");
Comments
Post a Comment