tags:

views:

85

answers:

1

I have a table and in each row is an an anchor element. How would I go about triggering the click of the href if the parent row is clicked anywhere in the row?

+1  A: 

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

Aaron
This can't work, since a tr element must have td elements as children. You are better served using the .find() method.
Bob
You caught me! I edited my answer to more correctly match the idea I was trying to get across. But you're right - using .find() would be easier since you don't need to know the structure of your `td` element to get the `a` element, especially if you use a more specific selector (ie specify the class of the `a`).
Aaron