user3850699 user3850699 - 7 months ago 7
HTML Question

How to add a hyperlink to a Table Row <tr>

I created a table, but i can't get the HTML link working, which I want to include in the tablerow.

<table class="list" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th width="10%"></th>
<th width="30%">Titel</th>
<th width="20%">Typ</th>
<th width="10%">Jahr</th>
<th width="14%">Anzahl</th>
<th width="8%"><img title="Dub" src="IMG" alt="Dub" /></th>
<th width="8%"><img title="Sub" src="IMG" alt="Sub" /></th>
</tr>
<td><img src="IMG" alt="" /></td>
<td style="padding-top: 15px;">XYXYXYXYXY</td>
<td style="padding-top: 15px;">XCXYX</td>
<td style="padding-top: 15px;">XYXYX</td>
<td style="padding-top: 15px;">XXXXX</td>
<td style="padding-top: 15px;"><img src="XYXYXYXYXY" alt="" /></td>
<td style="padding-top: 15px;"><img src="XYXYXYXYXY" alt="" /></td>
</tr>
<td><img src="XYXYXYXYXY" alt="" /></td>
<td style="padding-top: 15px;">XYXYXYXYXY</td>
<td style="padding-top: 15px;">XYXYXYXYXY</td>
<td style="padding-top: 15px;">XXXXX</td>
<td style="padding-top: 15px;">XYXYX</td>
<td style="padding-top: 15px;"><img src="XYXYXYXYXY" alt="" /></td>
<td style="padding-top: 15px;"><img src="XYXYXYXYXY" alt="" /></td>
</tr>
</tbody>
</table>


A fiddle: http://jsfiddle.net/pjPTd/

I tried it with using jquery, but i couldnt get it work.

Answer

To make a table row clickable, put the href inside of your row tag:

<tr href="http://www.example.com">

Then use this jquery: FIDDLE

$(document).ready(function(){
    $('table tr').click(function(){
        window.location = $(this).attr('href');
        return false;
    });
});