Jonas Raoni wrote:
[snip]
> showCoords = function(e){
> e = e.target || event.srcElement;
> alert("row: " + e.parentNode.rowIndex +
'ncell: ' + e.cellIndex);
> }
Jonas, your example didn't work for me in IE6 WinXP
('target' is null
or not an object). The following works in IE6:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01//EN"
"http:
//www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Show Cell Data</title>
<script type="text/javascript">
function showCoords(){
alert('row: ' + this.parentNode.rowIndex + 'ncell: ' +
this.cellIndex);
}
function init(){
for (var cells =
document.getElementById("t").getElementsByTagName(
"td"), i =
cells.length; i--; cells[i].onclick = showCoords);
/*
for beginners this might be easier to follow:
var cells =
document.getElementById('t').getElementsByTagName('td');
for (var i=0; i<cells.length; i++){
cells[i].onclick = showCoords;
}
*/
}
window.onload = init;
</script>
</head>
<body>
<table id="t">
<tr>
<td>Click me</td>
<td>Click me</td>
</tr>
<tr>
<td>Click me</td>
<td>Click me</td>
</tr>
</table>
</body>
</html>
|