Skip to content

Instantly share code, notes, and snippets.

@jsguy
Created July 24, 2013 01:29
Show Gist options
  • Save jsguy/6067483 to your computer and use it in GitHub Desktop.
Save jsguy/6067483 to your computer and use it in GitHub Desktop.
When using jQuery, and you need to select elements with weird IDs, this is handy
// Escape unwanted CSS selector chars
escapeForJquery = function(str) {
var charList = ["\\", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", "-", ",", ".", "/", ":", ";", "<", "=", ">", "?", "@", "[", "]", "^", "`", "{", "|", "}", "~"],
i, result = str;
for(i = 0; i < charList.length; i+=1) {
result = result.split(charList[i]).join("\\" + charList[i]);
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment