Thursday, July 9, 2009

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.

1 comments:

Denis St-Michel said...

Exactly what I was looking for. Thanks for posting this.

Post a Comment