Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make entire td a link?

How do I make this entire td a link?

<td id="blue-border"><span id="blue"></span></td>

Clicking td should make it behave like this (I know this is syntactically incorrect:

<a href="javascript:chooseStyle('blue-theme', 360)"> <td id="blue-border"><span id="blue"></span></td> </a>

EDIT: so far all the suggestions are only making the span inside the td a link, help lol.

like image 249
user784637 Avatar asked Jun 23 '11 19:06

user784637


People also ask

How do you make a whole row in a table clickable as a link?

Using <a> tag inside <td> One more way to make the whole row clickable is to add an <a> inside every <td> element. Along with it add hover to the row which we want to make clickable and use display: block property to anchor to make the whole row clickable.


3 Answers

Use CSS.

td a { display: block; width: 100%; height: 100%; }
<table style="width: 100%">
  <tr>
    <td><a href="#">Link</a></td>
  </tr>
</table>

The CSS forces the link to expand to the full width and height of the TD.

like image 118
Will Martin Avatar answered Sep 29 '22 19:09

Will Martin


You can't wrap a td in an anchor. Do this:

<td id="blue-border"><a href="javascript:chooseStyle('green-theme', 360)"> <span id="blue"></span></a></td> 

Or

<td onclick="chooseStyle('green-theme', 360)" id="blue-border"><span id="blue"></span></td>
like image 32
John Kalberer Avatar answered Sep 29 '22 18:09

John Kalberer


Add an anchor tag inside of the td and set its display attribute to block. This should make the entire td clickable.

#blue-border a{
    display: block;
}

or

<a href="link" style="display:block;">
like image 45
rolling stone Avatar answered Sep 29 '22 20:09

rolling stone