Griechenland, Mykonos

Trigger click on child by pressing <tr>

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 press the tr button to trigger a click <a>inside it.

I tried the following, but it does not work:

$('tr').click(function() {
    $(this).children('td.first a').click();
});
+3
source share
3 answers

Calling your own DOM-click method:

$(this).find('td.first a').get(0).click();
+4
source

If I remember correctly, jQuery click()only affects elements to which the jQuery handler is bound, and yours does not.

Perhaps an alternative to trying to force your own browser click event is to find hreflinks and simulate a click by simply moving it:

$('tr').click(function() {
    window.location = $('td.first a', this).attr('href');
});
+2
source

jquery.

$('tr').click(function() {
    $(this).children('td.first a').trigger( "click" );
});

.

-1

All Articles