I have my table with hover function on Rows, I am trying to change it to be hover on cells instead
Here’s my current script:
<script type="text/javascript">
window.onload=function(){
var tfrow = document.getElementById('tfhover').rows.length;
var tbRow=[];
for (var i=1;i<tfrow;i++) {
tbRow[i]=document.getElementById('tfhover').rows[i];
tbRow[i].onmouseover = function(){
this.style.backgroundColor = '#f3f8aa';
};
tbRow[i].onmouseout = function() {
this.style.backgroundColor = '#ffffff';
};
}
};
</script>
And here what i tried to change so far but still not working:
<script type="text/javascript">
window.onload=function(){
var tfcell = document.getElementById('tfhover').cells.length;
var tbCell=[];
for (var i=1;i<tfcell;i++) {
tbCell[i]=document.getElementById('tfhover').cells[i];
tbCell[i].onmouseover = function(){
this.style.backgroundColor = '#f3f8aa';
};
tbCell[i].onmouseout = function() {
this.style.backgroundColor = '#ffffff';
};
}
};
</script>
How can i achieve hover on cell instead of hover on row with my script?
You can use regular CSS for this purpose:
Thanks to @Mike Brant for pointing out the missing table id