The problem: when surrounding a table with an anchor tag, the table and everything within is not clickable in IE 6, 7 & 8. How do I solve this issue assuming I can't replace the table with divs?
Sample code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
<head>
<title>Test</title>
</head>
<body>
<a href="http://www.google.com">
<table height="35">
<tr>
<td>I'm a link in a table, bet you can'tclick me!</td>
</tr>
</table>
</a>
</body>
</html>
You can't have a table inside an anchor tag, as the table is a block tag and the anchor is an inline tag. Block tags don't go inside inline tags, so the code is invalid. Replacing the table with div elements doesn't work either, as they also are block elements.
The standards specifies how valid code should work, but not how invalid code should work. Different browsers have different methods of making the best of the situation. One alternative for the browser in this case is to move the anchor inside the table, another alternative is to move the table out of the anchor. Either method will give the desired result in some situations but not others.
The only way to reliably put a block element inside an anchor, is to use an element that is an inlinde element by default, and use CSS to turn both elements into block elements:
The code is valid as both elements are inline elements by default, and it works after the style is applied as a block element can be inside another block element.
I too got this problem today and searched for a fix, but couldn't find a working solution for it. So I just came up with this small jquery solution. You can modify it as you want. Hope this will give an idea to those of you struggling with this IE7 issue.
You can add href attribute directly to table insted of wrapping table in anchor tag.
use on click on table for navigating to corrosponding url
I've managed to find a solution for this, it's not perfect but it works:
Simplified CSS:
Simplified HTML:
Test page
Another way is using JavaScript event delegation on all links on IE9 like below:
Here is an alternative solution:
Why not do this?