Reputation: 345
I have the following:
<table>
<tr>
<td class="first"><a href="somelink">Griechenland, Mykonos</a></td>
<td class="second">test</td>
<td class="third">test</td>
<td class="last">699.-</td>
</tr>
</table>
I want when I click the tr, to trigger the click of the <a>
inside it.
I tried the following but it isn't working:
$('tr').click(function() {
$(this).children('td.first a').click();
});
Upvotes: 4
Views: 3454
Reputation: 74420
Call native DOM click method:
$(this).find('td.first a').get(0).click();
Upvotes: 5
Reputation: 107566
If I recall correctly, jQuery's click()
is only effective on elements that have a jQuery click handler attached to them, and yours do not.
Perhaps an alternative to trying to force a native browser click event is to find the href
of the link and simulate a click by simply navigating to it:
$('tr').click(function() {
window.location = $('td.first a', this).attr('href');
});
Upvotes: 2
Reputation: 533
Use jquery trigger method.
$('tr').click(function() {
$(this).children('td.first a').trigger( "click" );
});
Thanks.
Upvotes: -1