我有一个这样的 HTML 结构:
<tr class = "@rowOrdinal" id = "...">
<td>
<a href = "#">
<img src = "/Content/updateIcon.gif" class = "updateResourceImageButton" id = "..." />
</a>
<a href = "#">
<img src = "/Content/cancelIcon.gif" class = "cancelImageButton" />
</a>
</td>
<td class = "hiddenColumn" id = ...>...</td>
<td class = "resourceKeyColumn" id = ...>...</td>
... and so on...
单击更新链接时,我想获取对行的引用,即tr
更新超链接所在的元素。
因此,在下面的事件侦听器中,我想将 DOM 层次结构提升几级。我可以使用简单的 JavaScript 并使用while
循环来获取 . parentNode
,但是我将如何使用 jQuery 来做到这一点?
function WireHandlers() {
$('.updateResourceImageButton').click(UpdateResourceLinkClickedHandler);
}
function UpdateResourceLinkClickedHandler() {
// how do I get a reference to the tr that contains
// the hyperlink which is the source of this event?
}
$(document).ready(function () { WireHandlers(); });