0

I have an input with the name attribute:

<input type="text" name="data[foo][bar]" />

how can I select this element?

I tried $("input[name=data[foo][bar]]") but in vein.

4 Answers 4

11

Add quotes to the attribute value, otherwise you get conflicting square brackets and a parse error:

$("input[name='data[foo][bar]']")
Sign up to request clarification or add additional context in comments.

1 Comment

Yup, those quotes are actually mandatory.
0
$("input[name='data[foo][bar]']") 

Comments

0
$('input[name="data[foo][bar]"]')

http://api.jquery.com/attribute-equals-selector/ for more info

Comments

0

Use

$("input[name=data\\[foo\\]\\[bar\\]]")

The documentation says:

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").

http://api.jquery.com/category/selectors/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.