220
votes

How do I change the cursor pointer to hand when my mouse goes over a <tr> in a <table>

<table class="sortable" border-style:>
  <tr>
    <th class="tname">Name</th><th class="tage">Age</th>
  </tr>
  <tr><td class="tname">Jennifer</td><td class="tage">24</td></tr>
  <tr><td class="tname">Kate</td><td class="tage">36</td></tr>
  <tr><td class="tname">David</td><td class="tage">25</td></tr>
  <tr><td class="tname">Mark</td><td class="tage">40</td></tr>
</table>
11
For an interactive code snippet check my answerfmagno

11 Answers

377
votes

You can do this with CSS actually.

.sortable tr {
    cursor: pointer;
}
209
votes

I've searched bootstrap styles a bit and found this:

[role=button]{cursor:pointer}

So I assume you can get what you want with:

<span role="button">hi</span>
79
votes

The easiest way I've found is to add

style="cursor: pointer;"

to your tags.

25
votes

Add cursor: pointer to your css.

19
votes

I added this to my style.css to manage cursor options:

.cursor-pointer{cursor: pointer;}
.cursor-croshair{cursor: crosshair;}
.cursor-eresize{cursor: e-resize;}
.cursor-move{cursor: move;}
12
votes

For compatibility with IE < 6 use this style in that order:

.sortable:hover {
    cursor: pointer;
    cursor: hand;
}

But remember that IE < 7 supports :hover pseudoclass only with <a> element.

11
votes

Use the style cursor: pointer; in the CSS for the element you want the cursor to change on.

In your case, you would use (in your .css file):

.sortable {
    cursor: pointer;
}
10
votes

Use the CSS cursor property like so:

<table class="sortable">
  <tr>
    <th class="tname">Name</th><th class="tage">Age</th>
  </tr>
  <tr style="cursor: pointer;"><td class="tname">Jennifer</td><td class="tage">24</td></tr>
  <tr><td class="tname">Kate</td><td class="tage">36</td></tr>
  <tr><td class="tname">David</td><td class="tage">25</td></tr>
  <tr><td class="tname">Mark</td><td class="tage">40</td></tr>
</table>

Of course you should put the style into your CSS file and apply it to the class.

4
votes

Using css

table tr:hover{cursor:pointer;} /* For all tables*/
table.sortable tr:hover{cursor:pointer;} /* only for this one*/
4
votes

Example with styles inline:

<table>
  <tr> <td style="cursor: pointer;">mouse me over: pointer</td> </tr>
  <tr> <td style="cursor: wait;">mouse me over: wait</td> </tr>
  <tr> <td style="cursor: zoom-in;">mouse me over: zoom-in</td> </tr>
</table>
3
votes

for just a standard the above solutions work, but if you are using datatables, you have to override the default datatatables.css settings and add the following code to custom css, In the code below row-select is the class that I added on datatables as shown in the html.

table.row-select.dataTable tbody td
{
cursor: pointer;    
}

And you html will look as below:

<table datatable="" dt-options="dtOptions1" dt-columns="dtColumns1" class="table table-striped table-bordered table-hover row-select"  id="datatable"></table>