-4

When I insert the text "()" inside the :contains() Selector, I am getting the following error

    Uncaught Syntax error, unrecognized expression: "X(") 

I will give my sample

   $("div#list li:contains("X(")").remove();

How to overcome this?

EDIT : I am using jquery-1.4.1.

karthik
  • 17,453
  • 70
  • 78
  • 122

3 Answers3

2

Just use one string with '

$('div#list li:contains("X(")').remove();

Edit: in version 1.4.1 there was yet a bug with :contains selector's escaping. In this case you have to write your own RegExp to find the element:

var searchRegex = new RegExp("X\\(", "g"),
    result = $('div#list li').filter(function (i, el) {
        return $(el).text().match(searchRegex);
    });
result.remove();
Niccolò Campolungo
  • 11,824
  • 4
  • 32
  • 39
2

It is an escaping issue but it would be much simpler to do this:

 $('div#list li:contains("X(")').remove();

or

 $("div#list li:contains('X(')").remove();
Andy
  • 14,427
  • 3
  • 52
  • 76
0

This is the correct answer

$("div#list li:contains('X(\")')").remove();

Check http://jsfiddle.net/4F3JF/

Manish Jangir
  • 505
  • 3
  • 9