[jQuery] Retrieving values from elements of the same class
For the following code:
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<script type"text/javascript">
$(document).ready(function()
{
$('.approve').click(function() {
alert($('.approve').prev().val());
});
});
</script>
<div>
<input type="hidden" value="1" />
<input type="button" class="approve" value="Approve" />
</div>
<div>
<input type="hidden" value="2" />
<input type="button" class="approve" value="Approve" />
</div>
<div>
<input type="hidden" value="3" />
<input type="button" class="approve" value="Approve" />
</div>
Each time I click on any of the button, it's returning me 1. What
should I change in my javascript code to get the proper values 1, 2 or
3?