I have
<div id="exp">
<input type="hidden" name="sum[]" value="1" />
<input type="hidden" name="sum[]" value="2" />
<input type="hidden" name="sum[]" value="3" />
<input type="hidden" name="sum[]" value="4" />
</div>
And I want in jquery get the value of the last element of the array. I’ve tried:
alert(sum[sum.length-1]);
But shows me ‘undefined’. What am I doing wrong?
You can use this:
This uses a jQuery selector to find the last
inputelement that is a child of#expand get its value.You can see it work here: http://jsfiddle.net/jfriend00/Lh7sJ/