window.onload = function () {
var tbl = document.getElementById('tbl');
var tr = tbl.getElementsByTagName('tr');
for (var i = 0; i < tr.length; i++) {
var first_td = tr[i].getElementsByTagName('td')[0];
first_td.onmouseover = function () {
hover('on');
}
first_td.onmouseout = function () {
hover('off');
}
}
function hover(state) {
for (var i = 0; i < tr.length; i++) {
var first_td = tr[i].getElementsByTagName('td')[0];
if (state == 'on') {
first_td.style.color = 'White';
first_td.style.background = 'RED';
}
else if (state == 'off') {
first_td.style.color = '#000';
first_td.style.background = '#fff';
}
}
}
}
I do this but this code not working for all table column. in this code there only any one column are worked. other column are not working. please provide the code for the change all the column change color on hover.