Posted By

bitstream on 02/01/11


escape jquery

Versions (?)

jquery escape meta chars

 / Published in: JavaScript

f you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;[email protected][]^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: \. For example, if you have an an element with id="", you can use the selector $("#foo\.bar").

  1. function jqescape(str) {
  2. return str.replace(/[#;&,\.\+\*~':"!\^\$\[\]\(\)=>|\/\\]/g, '\\$&');
  3. }

Report this snippet  

You need to login to post a comment.