Experiences on the Front Lines of User Interfaces and Web Development

jQuery select of a name field that has square brackets

Suppose you have the following input field:
<input type="text" name="users[][name]" value="John" />

You will recognize this as rails notation for being able to send a collection of user objects to the server in a post. (Other web frameworks use it as well).

If you want to find that input field in jQuery, do:
jQuery( '[name="users[][name]"]' );

The trick is to put the string you are looking for in double quotes, which means you then have to wrap the entire jQuery parameter in single quotes.

Comments

Denis St-Michel
Exactly what I was looking for. Thanks for posting this.

comments powered by Disqus