tirenweb
tirenweb

Reputation: 31719

HTML: is there any way to make clickable <td> o <tr> tags?

Is there any way to make clickable <td> or <tr> tags?

Upvotes: 5

Views: 10447

Answers (7)

Prasath
Prasath

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

Bob
Bob

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

Matteo Italia
Matteo Italia

Reputation: 126827

If I understood correctly what you mean:

<td id="yourcell">Just a useless cell</td>

...
<a href="yourpage.html#yourcell">link</a>

Reference

Upvotes: 1

Pekka
Pekka

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

David Thomas
David Thomas

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

Thilo
Thilo

Reputation: 262554

<td><a name="foo"/>bar</td>

Upvotes: 1

Lie Ryan
Lie Ryan

Reputation: 64855

<td><a href="foo">bar</a></td>

Upvotes: 5

Related Questions