0

How do you refer to elements of array in Jquery? For instance - input type of text with name="a[]" attribute.

Facundo Casco
10.7k8 gold badges45 silver badges66 bronze badges
asked Oct 19, 2010 at 15:27

1 Answer 1

5

You can select them with an attribute-equals selector on the name attribute, like this:

$("input[name='a[]']")

This will get you all elements, if you want one at a specific index as a jQuery object use .eq(), or as a DOM element use .get(), like this:

$("input[name='a[]']").eq(0) //first element wrapped in jQuery object
$("input[name='a[]']").get(0) //first raw DOM element
answered Oct 19, 2010 at 15:30
Sign up to request clarification or add additional context in comments.

1 Comment

Nitpicking: Since it was also specified that the input type be limited to text, the more correct selector would be $("input[name='a[]'][type=text]").

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.