javascript - why jquery id selector not support special character -
when using special character find element below $("#search@")
exception occur. how resolve it? i've tried using special character it's working *
character $("#search*")
without error, others #$%^&()
throw error.so why accepts * character why other character doesn't.
if have special character id
s, should escape them using \\
(two backslashes) when access them. far know allowed html5
.
as stated in jquery
selector documentation
to use of meta-characters ( such !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) literal part of name, must escaped with 2 backslashes: \. example, element id="foo.bar", can use selector $("#foo\.bar").
alert($("#search\\$").html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <div id="search$">heh</div>
Comments
Post a Comment