I can't seem to get this code to work. How do I get the closest value of .abc when the button is clicked?
Defining Closest
ie: if you click the button where "A:" is at I want a value of 10. if you click the button listed in "B:" I want the value of 20.
Here is the code:
<script type="text/javascript">
$(function(){
$('.test').click(function(){
var value = $(this)
.parent()
.parent()
.closest(".abc")
.attr("value")
alert(value);
return false
});
});
</script>
<form name="myform">
<table>
<tr>
<td>A:</td>
<td><input type="text" class="abc" name="a" id="a" value="10" /></td>
<td><input type="text" name="vbn" id="vbn" /></td>
<td><input type="text" name="mkl" id="mkl" /></td>
<td><input type="button" class="test" name="test" id="test" value="test" /></td>
<td>B:</td>
<td><input type="text" class="abc" name="b" id="b" value="20" /></td>
<td><input type="text" name="ews" id="ews" /></td>
<td><input type="text" name="hrs" id="hrs" /></td>
<td><input type="text" name="ew3" id="ew3" /></td>
<td><input type="text" name="3ws" id="3ws" /></td>
<td><input type="button" class="test" name="test" id="test" value="test" /></td>
</tr>
<tr>
<td>C:</td>
<td><input type="text" class="abc" name="c" id="c" value="30" /></td>
<td><input type="text" name="oiu" id="oiu" /></td>
<td><input type="text" name="dfe" id="dfe" /></td>
<td><input type="button" class="test" name="test" id="test" value="test" /></td>
</tr>
<tr>
<td>D:</td>
<td><input type="text" class="abc" name="d" id="d" value="40" /></td>
<td><input type="button" class="test" name="test" id="test" value="test" /></td>
</tr>
</table>
</form>