(From JQuery Docs -> Selector)
If you wish to use any of the meta-characters described above as a literal part of a name, you must escape the character with a backslash (\). Since Javascript uses the backslash for escape sequences in string literals, you must use two backslashes (\\) in string literals so that a single backslash will be put into the string 1.The full list of characters that need to be escaped:
#;&,.+*~':"!^$[]()=>|/
I have a suggestion: How about adding a method to escape values for use in a JQuery Selector?
I have an array of special-character containing strings that need passed into a JQuery selector. I am escaping these strings using: str.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/])/g,'\\$1') before passing them into the selector. To me, it seems like a good idea to have an equivalent function built into JQuery for escaping these characters. Especially if the list of special characters were to change over time, a built-in escape method would always work with whatever version of JQuery was running.
I searched the forums to see if this had been discussed before but I did not find what I was looking for.
What do you guys think? Is this a good idea, or unnecessary bloat?