I’ve tried to search for a user-agent string in a table using jQuery. If I search like this it is not found:
jQuery("table.make-html-table
td:contains('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)')")
.css("background","yellow");
If I search like this – slashes before \( – then it give me an error:
jQuery("table.make-html-table
td:contains('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)')")
.css("background","yellow");
Error:
"Syntax error, unrecognized expression: (comp...
How can I properly escape that string so that I can search for cells that contain it with jQuery?
The relevant part in sizzle is
which makes me think there is no way. Looks like it only accepts arguments that contain no parenthesis at all, or only one level thereof like
:contains("(foo)"). An obvious improvement would be accept anything if an argument is quoted, hope this will be fixed soon.For the time being, a workaround would be to write a selector that would accept escaped arguments, for example:
usage:
In action: http://jsfiddle.net/9wWP5/