escapeSelector = function (selector) {
  return selector.replace(/([ \!\"\#\$\%\&\'\(\)\*\+\,\.\/\:\;<\=\>\?\@\[\\\]\^\`\{\|\}\~])/g, '\\$1');
}
Escapes selector name for use with jQuery

All meta-characters listed in jQuery doc are escaped:
http://api.jquery.com/category/selectors/

@function
@param {String} selector The jQuery selector to escape
@return {String} The escaped selector.