How to select all input with given name if name contains [ and ]?
$('input[name=field_name[array_key]]').removeClass('select开发者_如何学Goed');
Console:
Uncaught Syntax error, unrecognized expression: [name=field_name[array_key]]
Thank you for answers!
$('input[name=field_name\\[array_key\\]]').removeClass('selected');
escape the special characters like []
characters
$('input[name=field_name\\[array_key\\]]').removeClass('selected');
You need to escape with "\\
"
From Jquery docs:
If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: \. For example, if you have an element with id="foo.bar", you can use the selector $("#foo\.bar")
Put the name
value in quotes:
$('input[name="field_name[array_key]"]').removeClass('selected');
As stated by the jQuery docs:
Quotes are mandatory
Here's a live example of the above code.
精彩评论