Links within a Table

Is there a way to make an entire cell within a table, a link? Not just the text but the whole cell.
Who is Participating?
jbirkConnect With a Mentor Commented:
Well, no, not really.  You could just use a normal link which started at the beginning and ended at the end of the table cell, but that would only link the elements within the cell, not the entire cell.

You could use some 4th generation event handling to grab the mouseclick and determine if it's in that table cell and then take some action if it is.  But this is pretty complicated and only works in netscape and IE 4+ browsers.  I'm not even totally sure that it will work with table cells, but I suppose it may be possible.  Probably more likely to work in IE 4 than netscape 4.

I'll look into this if you'd like, but I have a feeling it'll be a no go.
If you want to pursue the event model you may be better off using layers.  I think it will work with layers like you want, but then you lose the table formatting...
SkadfatherAuthor Commented:
yeah i would rather not lose the Table format. and i would prefer to have most people able to use it (not limiting it to only those with IE4+ )
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

It was as I suspected.  It will work only in IE.  Here's a short example on how to do this in IE 4:
<TABLE border=1><TR><TD>
Here is a table cell
<img src="cards_off.gif" width=200 height=50 border="0" name="Cards off">
<TD id="testing">another table cell
<img src="cards_on.gif" width=200 height=50 border="0" name="Cards on">
</TD><TD>yet another table cell
<img src="Hdhp.gif" width=116 height=13 border="0" name="Hdhp">
<SCRIPT language="JavaScript1.2">
<!-- cloak

var isIE = (navigator.appName.indexOf("Microsoft") != -1);

if (isIE)

function handler()
 {alert('You clicked inside the table cell!');
// decloak -->

Basically I had to use id to make a name for the second table element. Then it tells the browser to capture the mousedown event on that element, and then it calls the handler function when that occurs.

Sorry if this spoils any plans, but it simply won't work exactly as you want it to.  EIther it only works in IE 4 but does what you want exactly, or you need to use layers to get it to be more cross platform but won't work exactly as you want it to.

SkadfatherAuthor Commented:
Too much trouble... and it wouldn't work on browsers other than IE4. would you mind if i kept the question open for a bit... if nobody else can give me an answer than ill grade it.
Be my guest, but I really think that there is no other way to make an actual table cell link to something (other than the alternatives I mentioned)...

Note that if all that is in the table cell is an image you can just use a link around the image, but since you asked about the whole cell, I'm assuming you have more than just an image in the cell.

The simple way of achieving this would be to make the table cell contain an image either blank or with the text for the link as part of the image. The background of the image could be transparent to match the rest of the table.

The image would then go between the normal <A HREF> tags. This would then present no problems in any browser and needs no scripts or anything else.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.