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