Reputation: 5442
I have the following HTML:
<table>
<tr><td>...</td><td><input type="hidden" name="price[1]" value="10"></td><td>...</td>
<tr><td>...</td><td><input type="hidden" name="price[6]" value="230"></td><td>...</td>
<tr><td>...</td><td><input type="hidden" name="price[7]" value="40"></td><td>...</td>
<tr><td>...</td><td><input type="hidden" name="price[10]" value="10"></td><td>...</td>
</table>
I have also got that this is important to say that they are stored in table
td
s and it's preferred not to bring them out of the table. (So I updated the code to be more like in real)
What I want, is a way to select one of them by their index()
number to be able to get their val()
.
I know that their index
is counted from 0
to 3
. I want to get the val()
of the second one with index(1)
.
Upvotes: 1
Views: 2712
Reputation: 781340
To get the value of the second hidden input:
$('input[type=hidden]:eq(1)').val()
Upvotes: 4
Reputation: 22323
try:
var a="";
$("input[type=hidden]" ).each(function( index ) {
a+=($(this).val()) + ",";
});
alert(a);
Upvotes: 1
Reputation: 7380
DEMO http://jsfiddle.net/yeyene/yGCP2/
$(document).ready(function(){
$('input[type=hidden]').each(function(){
alert($(this).val());
});
});
Upvotes: 1
Reputation: 1427
In jQuery it would be:
$('input[type="hidden"]');
http://jsfiddle.net/mattydsw/32NU8/
Upvotes: 1