Click to See Complete Forum and Search --> : colgroup or col associated even
jak123
05-06-2007, 06:05 AM
I am trying to associate events with entire columns in a table, but its not working (with both 'colgroup' or 'col'). If it should/can work, how?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
</head>
<body>
<div >
<table width="50%">
<colgroup span="1" onmouseover="javascript:alert('SDF')" />
<tr>
<td> Home1 </td>
</tr>
<tr>
<td> Home2 </td>
</tr>
</table>
</div>
</body>
</html>
It should, but support for colgroup/col is patchy in all browsers.
Incidentally the minimized tag syntax is not permitted:Start tag: required, End tag: optional (http://www.w3.org/TR/html4/struct/tables.html#h-11.2.4.1)
A JavaScript solution:<script type="text/javascript">
window.onload=function() {
var aTR=document.getElementById('table1').getElementsByTagName('tr');
for(var i=0; i<aTR.length; i++) {
if (aTR[i].cells[0].addEventListener) { // W3C
aTR[i].cells[0].addEventListener('mouseover', function() {alert('SDF'); }, false);
}
else {
aTR[i].cells[0].attachEvent('onmouseover', function() {alert('SDF'); } );
}
}
}
</script>
WebJoel
05-06-2007, 08:48 AM
I don't understand what you're trying to do, but here's something to look at:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
</head>
<body>
<div >
<table width="50%" border="1">
<tr>
<th width="50%" span="first onmouseover="javascript:alert('SDF')">First</th>
<th width="50%" span="second" onmouseover="javascript:alert('SDF-2')">Second</th></tr>
<tr>
<td> Home1 </td>
<td> Home2 </td>
</tr>
<tr>
<td> Home3 </td>
<td> Home4 </td>
</tr>
</table>
</div>
</body>
</html>