1
<select name="search[quick_dates]" id="search_quick_dates">
...
</select>

and jQuery:

f.find('select[name=search[quick_dates]]').bind('change', { form: f }, function(e){
...
}

throws an error:

Uncaught Error: Syntax error, unrecognized expression: select[name=search[quick_dates]]

Can I update my jQuery instead of changing the attribute name?

eozzy
  • 66,048
  • 104
  • 272
  • 428
  • possible duplicate of [jQuery selector for inputs with square brackets in the name attribute](http://stackoverflow.com/questions/2364982/jquery-selector-for-inputs-with-square-brackets-in-the-name-attribute) – JJJ Jan 17 '15 at 12:18

2 Answers2

2

To use any of the meta-characters such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ as a literal part of a name, it must be escaped with with backslashes:

Change it:

f.find('select[name=search[quick_dates]]')

To this:

f.find('select[name="search\\[quick_dates\\]"]')
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
  • Tried that already: `Uncaught Error: Syntax error, unrecognized expression: select[name=search\["quick_dates"\]]` – eozzy Jan 17 '15 at 12:03
  • It is double, copy-pasted from here but chrome reports it that way (single backslashes) – eozzy Jan 17 '15 at 12:05
1

You will need to escape brackets. But using single backslashes will not escape brackets because single backslash will escape the character in the string inside the function but you need backslash to be part of the expression or selector and hence you will also have to escape backslash by another backslash.

Try this:

f.find('select[name=search\\[quick_dates\\]]')
ksg91
  • 1,279
  • 14
  • 34