Reputation: 7792
I have a bunch of text areas that are children of a div that has an id. I want to get the text in each of those text areas in an array - so is there a way in jquery to get all the children that are of a certain type(in this case text area) of a certain parent?
I've tried this -
$("#optionGroup_0").children('input[type=text], textarea');
but that returns an empty array. I think the above method would work if I had the right selector for a text area, but I'm not sure.
Can anyone help?
Upvotes: 0
Views: 256
Reputation: 50643
You can do it like so:
var array = $("#optionGroup_0 textarea").map(function() {
return $(this).val();
}).get();
See working demo
Upvotes: 4
Reputation: 98758
.find()
is every descendant, where .children()
goes only one level deep. See: api.jquery.com/find
$("#optionGroup_0").find('input[type=text], textarea');
Upvotes: 1