Reputation: 187
Given the html:
<div id="rearGearInputContainer">
<input id="rear1"></input>
<input id="rear2"></input>
<input id="rear3"></input>
<input id="rear4"></input>
</div>
In the Chrome console I type:
$('#rearGearInputContainer').find("input").each(function () {return $(this).val();})
And the result is an array of html:
[<input id="rear1">, <input id="rear2">, <input id="rear3">, <input id="rear4">]
...not an array of the input field values as I'd expect. Can anyone explain why? Thanks.
Upvotes: 0
Views: 1000
Reputation: 36784
You are trying to return in an each method, which I don't think you want. I think you mean to use the map()
method:
var vals = $('#rearGearInputContainer').find("input").map(function () {
return $(this).val();
}).get()
Upvotes: 5
Reputation: 22480
$('#rearGearInputContainer input').each(function () {
alert($(this).val());
})
Upvotes: 0