Need to escape a special character in a jQuery selector string

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-05-07T06:07:51Z Indexed on 2010/05/07 6:18 UTC
Read the original article Hit count: 202

Filed under:
|

According to the selectors docs, you must escape [ with double backslash, etc \\[.

I have a selector that is created like so (assume val attribute is something[4][2] in this example).

var val = $(this).attr('val');           

$select.find('option[value=' +  val + ']').show();

Can I write a regex to escape the brackets for me?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript