Created
July 24, 2013 01:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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