Need to escape a special character in a jQuery selector string
- by alex
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?