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 ids, 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

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -

python - build a suggestions list using fuzzywuzzy -