I want to get value inside span with id ‘TargetSpan’ when user clicks on Input with ID of ‘test’
I tried this code but it returns null.
$('.PrintReport').click(function (e) {
alert($(this).parent().find('td:eq(2)').html());
});
<tr>
<td>
</td>
<td>
</td>
<td>
<span id="TargetSpan" class="Price">0</span>
</td>
<td>
</td>
<td>
<input id=test type="image" class="PrintReport" >
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<span id="TargetSpan2" class="Price">0</span>
</td>
<td>
</td>
<td>
<input id=test2 type="image" class="PrintReport" >
</td>
</tr>
I guess this is what you are looking for and of course this solution relative to your HTML mark-up and might not work if you change your mark-up.
this is another solution but you have to give every
TargetSpanandTestid’s with a number suffix likeTargetSpan1,TargetSpan2,test1,test2