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?
Asked
Active
Viewed 3,652 times
1 Answers
2
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
- 6,988
- 4
- 31
- 48
-
This can't work, since a tr element must have td elements as children. You are better served using the .find() method. – Bob Mar 08 '10 at 20:04
-
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 Mar 08 '10 at 20:14
-
Didn't work and I got this `Uncaught RangeError: Maximum call stack size exceeded` – Elshan Sep 24 '17 at 09:39