开发者

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

开发者 https://www.devze.com 2022-12-22 02:28 出处:网络
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

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

精彩评论

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