jquery escape meta chars


/ Published in: JavaScript
Save to your folder(s)

f you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;?@[\]^`{|}~ ) 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="foo.bar", you can use the selector $("#foo\\.bar").


Copy this code and paste it in your HTML
  1. function jqescape(str) {
  2. return str.replace(/[#;&,\.\+\*~':"!\^\$\[\]\(\)=>|\/\\]/g, '\\$&');
  3. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.