Reputation: 31719
Is there any way to make clickable <td>
or <tr>
tags?
Upvotes: 5
Views: 10447
Reputation: 106
Here is the correct way to make it using jquery.
$(document).ready(function() {
$('#tableid tr').click(function() {
var href = $(this).find("a").attr("href");
if(href) {
window.location = href;
}
});
});
If you want make all the cells are clickable you need to mention "td" in click function.
Upvotes: 0
Reputation: 51
<td onclick="window.location = 'index.html';">cell content</td>
index.html above can be any URL or internal page link. Note: the mouse pointer does not turn into a pointing hand when you mouse over the cell using this javascript method, but clicking on the cell does take you to the URL.
Upvotes: 5
Reputation: 126827
If I understood correctly what you mean:
<td id="yourcell">Just a useless cell</td>
...
<a href="yourpage.html#yourcell">link</a>
Upvotes: 1
Reputation: 449525
<td>
s can have a JavaScript onclick
event.
Other than that, putting an <a>
into the table cell, and giving it a fixed width to fill the table (you need to make it display: block
for that) is the most reliable way.
Upvotes: 1
Reputation: 253328
To turn non-link tags into links, use @Lie Ryan's answer and put an a
into the element.
To be able to link to an element:
Use an a
<a href="#idOfTheElement">Link to the element</a>
and a named point:
<td id="idOfTheElement">contents</td>
Upvotes: 3