div with the id="(name)" can I use this or not?
This question already has an answer here:
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
http://api.jquery.com/category/selectors/
can you please check this jsfiddle
$(document).ready(function() {
$("#RSI(3,4)").html("some text");
});
Working Fine
链接地址: http://www.djcxy.com/p/15450.html上一篇: jQuery循环中div的不同CSS