Highlighting rows with mouse move : tr « Tags « HTML / CSS






Highlighting rows with mouse move

  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head>
<title>Highlighting rows</title>
<meta http-equiv="content-type"
    content="text/html; charset=utf-8" />
<style>

.datatable {
  border: 1px solid #D6DDE6;
  border-collapse: collapse;
  width: 80%;
}
.datatable td {
  border: 1px solid #D6DDE6;  
  padding: 0.3em;
}
.datatable th {
  border: 1px solid #828282;
  background-color: #BCBCBC;
  font-weight: bold;
  text-align: left;
  padding-left: 0.3em;
}
.datatable caption {
  font: bold 110% Arial, Helvetica, sans-serif;
  color: #33517A;
  text-align: left;
  padding: 0.4em 0 0.8em 0;
}

.datatable tr:hover, .datatable tr.hilite {
  background-color: #DFE7F2;
  color: #000000;
}
    </style>
</head>
<body>
<table summary="List of new students 2003" class="datatable">
  <caption>Student List</caption>
  <tr>
    <th scope="col">Student Name</th>
    <th scope="col">Date of Birth</th>
    <th scope="col">Class</th>
    <th scope="col">ID</th>
  </tr>
  <tr>
    <td>Title</td>
    <td>27/08/1997</td>
    <td>Title</td>
    <td>12009</td>
  </tr>
  <tr>
    <td>Title</td>
    <td>20/07/1997</td>
    <td>Title</td>
    <td>12010</td>
  </tr>
  <tr>
    <td>Title</td>
    <td>21/07/1997</td>
    <td>Title</td>
    <td>12030</td>
  </tr>
  <tr>
    <td>Title</td>
    <td>19/03/1997</td>
    <td>Title</td>
    <td>12021</td>
  </tr>
  <tr>
    <td>Title</td>
    <td>18/05/1997</td>
    <td>Title</td>
    <td>12022</td>
  </tr>
  <tr>
    <td>Title</td>
    <td>17/07/1997</td>
    <td>Title</td>
    <td>12019</td>
  </tr>
  <tr>
    <td>Title</td>
    <td>04/04/1997</td>
    <td>Title</td>
    <td>12007</td>
  </tr>
</table>
<script type="text/javascript">
var rows = document.getElementsByTagName('tr');
for (var i = 0; i < rows.length; i++) {
  rows[i].onmouseover = function() {
    this.className += ' hilite';
  }
  rows[i].onmouseout = function() {
    this.className = this.className.replace('hilite', '');
  }
}
</script>
</body>
</html>

   
    
  








Related examples in the same category

1.'tr' Example
2.table row with class
3.Table style for even rows
4.Set different colors for even and odd table row
5.table row background
6.table row hover
7.stripe table with Javascript
8.Coloring Rows in a Table
9.Selecting cells in row
10.Alternating Row Background
11.Alternating row colors
12.Table with subtotoal row
13.Hiding row
14.tr height: 30px;
15.tr background: #EFEFEF;
16.tr background: url(img/menubg2.gif) repeat-x bottom left #eaeaea;
17.tr color: #505050;
18.tr padding: 7px;
19.tr text-align: left;