Make <tr> to act like

I have a table and I want each row to be clicked. Now I am doing simple:

$('tr').click(...)

This works for the most part, but how can I get it to act as a link in the following ways:

  • Shift-click opens target in a new window
  • Middle press opens the target in a new tab
  • Hovering the link shows the link address in the status bar
+3
source share
6 answers

This is technically possible in some browsers, but not for everyone, and for those who support it, this is a lot of work. You must capture keyboard events without a left click. You should probably just wrap the contents of each TD in a regular A tag.

JS/override ... , , , ​​ HREF, JavaScript.

+11

.mouseUp() shift ctrl, . , , , .

, <a> , , . jQuery :

$('tr th, tr td').wrapInner('<a href="..."></a>').children('a').click(function() {
    ...
});
+7

<a> :

<table>
<tr>
  <td><a href="...">...</a></td>
  <td><a href="...">...</a></td>
  <td><a href="...">...</a></td>
</tr>
</table>

CSS:

table.clickRows td > a {
  display: block;
  width: 100%;
  height: 100%;
}
+3

, , <a> , "" .

, , .

+1

<a> <tr>.

, <a>, , .

+1

, Apple - , - . , .

<a> , , -, <tr>.

+1

Source: https://habr.com/ru/post/1714826/


All Articles