Reputation: 1844
I need to find the id of an image button (within table cell 1) on clicking another image button (within table cell 2).
I cannot hardcode any index in my javascript / jquery.
Is there any other way to fetch the id of the second button within that particular row of a table?
Please help
Code Sample
<tr class="home-history-grid-row">
<td>
<img id="test" height="16px" width="16px" onclick="changeImage(this)" src="SiteImages/deleteconfirm.png" title="Confirm Delete" alt="Delete">
</td>
<td>
<input id="ctl00_Content_NotificationHistory_ctl02_ImgDelete" type="image" style="height: 16px; width: 16px; border-width: 0px;" src="SiteImages/X.gif" clientidmode="Static" disabled="disabled" name="ctl00$Content$NotificationHistory$ctl02$ImgDelete">
</td>
</tr>
Upvotes: 0
Views: 187
Reputation: 6703
The following code must solve your problem:
function changeImage(elm) {
var otherImageId = $(elm).parent().next().find("input:first").attr("id");
// ... use otherImageId here ...
}
Upvotes: 0
Reputation: 10989
If I understand you correctly you need to find the id of the input from clicking the image? If so, then this would do it for you:
function changeImage(self) {
$(self).closest('tr').find('td input').attr('id');
}
Upvotes: 1