How can I get the previous input value in the fiddle below? I get undefined unless they are in the same span.
<span>
<input type="text" value="48.00" >
</span>
<span>
<input type="text" value="44.00" >
</span>
$('input[type=text]').click(function () {
alert($(this).prevAll("input[type=text]").val());
});
prevAllfinds siblings. Those are not siblings. Thespans they’re in are, though, so:Note that if you’re using
prevAll, you may end up with multipleinputelements in the result. Callingvalon the result will only give you the value of the first of them.