[jQuery] return value of previous element confusion
I am having a bit of difficulty with this; I have a few similiar divs
that share a class name:
<div class="test">
<input name="id" type="hidden" value="1" />
<div>
<input type="submit" /></div>
<div>
<div class="test">
<input name="id" type="hidden" value="2" />
<div>
<input type="submit" />
<div>
<div class="test">
<input type="hidden" value="3" />
<div>
<input name="id" type="submit" />
</div>
<div>
Now if I try find the value of the first:
$("input[type=submit]").click(function(ev){
ev.preventDefault();
console.log($
(this).parent().prevAll("[name=id]:first").val());
}
i get the object returned once which is what I want, however, after
that the object is returned an incremental number of times:
the second query y will return:
2
2
the third on:
3
3
3
It seems that jquery is matching all the occurences of "classname"
with the returned val(); how can I just limit the value to $(this)
<--- this! this! this! occurence of className ????