Can I use id with "("
and ")"
in jquery mobile ?
for example:
<div id="RSI(3,4)">
</div>
I have tried that id and want to access that element in js.
$("#RSI(3,4)").html("some text");
but it didn't worked.
Can I use id with "("
and ")"
in jquery mobile ?
for example:
<div id="RSI(3,4)">
</div>
I have tried that id and want to access that element in js.
$("#RSI(3,4)").html("some text");
but it didn't worked.
Escape the special chars
$("#RSI\\(3\\,4\\)").html("some text");
http://api.jquery.com/category/selectors/
To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar").
That said, about the validity of using special characters in an ID, some validators would complain and I do certainly NOT recommend using any special chars in an ID nor use leading digits just because you can according to the latest html specs. Make your life easier and use only a-zA-Z0-9 and if needed, underscore
W3C Validator says that this html code
<html>
<head>
<title>TITLE</title>
</head>
<body>
<div id="RSI(3,4)"></div>
</body>
</html>
is valid for html5 but not for html4.01 Strict, for which (
is invalid character in id
attribute.
http://validator.w3.org/check
In jQuery you have to escape them with \\
can you please check this jsfiddle
$(document).ready(function() {
$("#RSI\\(3\\,4\\)").html("some text");
});
Working Fine