Varun Varun - 5 months ago 36x
jQuery Question

jquery :contains giving error: jquery-1.12.3.js:1502 Uncaught Error: Syntax error, unrecognized expression: contains("sys")

I am trying to implement a filter which will filter "pre" html element when text matches with what user is entering in an input html element.

But it doesn't seems to work when i try to check it with what user is entering, but works if i hardcode the text to be searched.

Here's my js script:

.change( function () {
var filter = $(this).val();
if(filter) {

} else {

return false;
.keyup( function () {

}); });

If i hardcode the "filter" to some string in "pre" elements it works.
for eg: one of the string has "sys" in it, so if i hardcode like:
: it hides the element.


The second line for hiding,


is converted to


which throws unrecognized expr for (contains(..))

It should be with : for contains() - final evaluation to :not(:contains(...))

//                       ^

Fiddle Demo