开发者

jQuery, how to trigger an href click on when a parent row is clicked

I have a table and in each row is an an anchor element. How w开发者_JS百科ould I go about triggering the click of the href if the parent row is clicked anywhere in the row?


Assuming you mean a table row, the you would add a click handler to the row that simply clicked the child a tag:

$("tr").click(function() {
    $(this).children("td > a").click();
    return false; // Prevent event propagation and infinite loops
});

EDIT: Thanks to Tatu for reminding me about event propagation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜