I have something like:
<tr><td><a href="...">text</a></td>...</tr>
I need to enable user to click on entire table row to navigate on that link.
Now I use the following code:
$(function () {
$('tr').each(function () {
var tr = $(this);
if (tr.hasClass('no-row-link')) return;
var links = $('a', tr);
if (links.length != 1) return;
tr.addClass('row-link').click(rowLinkClick);
});
function rowLinkClick() {
var tr = $(this);
var links = $('a', tr);
if (links.length != 1) return;
window.location = links.attr('href');
}
});
but the problem is, this behaviour is not working very nice. User can command-click on normal link to open page in new tab, but he can't here. User can right-click on normal link to view link context menu, but he can't here.
The only way I can do what I want is to iterate throw table cells (th/td) and wrap their contents on links. And then make those links behave with display:block. This isn't very elegant solution. Is there any other solutions for that?