How do you refer to elements of array in Jquery? For instance - input type of text with name="a[]" attribute.
+1
A:
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
Nick Craver
2010-10-19 15:30:44
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]").
nnevala
2010-10-19 15:38:52
Thanks a lot you guys.
Andrew
2010-10-20 20:55:48