jQuery selector escaping

Published:

jQuery selectors are powerful and simple to use, until you have attribute values (including ids and classes) that have funny characters. I wrote a plugin adds a simple function $.escape that will escape any special characters. For example if I have a string s that contains an id but I'm not sure that all of the characters are safe I can use $('#'+$.escape(s)) to find the element with that id. If I want to find all of the links to http://ianloic.com/ I can do $('a[href='+$.escape('http://ianloic.com/')+']')

The first release is here. I don't know that there will be any more releases - this is a pretty damn simple plugin.