§ Table row hover highlight
A bit of javascript to highlight the table row under the cursor.
function removeName(el, name) {
//don't waste time
if(el.className.indexOf(name)<0)
return;
var i, curList, newList;
// Remove the given class name from the element's className property.
newList = new Array();
curList = el.className.split(" ");
for (i = 0; i < curList.length; i++)
if (curList[i] != name)
newList.push(curList[i]);
el.className = newList.join(" ");
}
function trMouseover() {
this.className+=' resultrowhighlight';
}
function trMouseout() {
removeName(this,'resultrowhighlight');
}
function addTrMouseEvents() {
var trlist=document.getElementsByTagName("tr");
for(var i=0;i<trlist.length;i++) {
if(trlist[i].className.indexOf('resultrow')>-1) {
trlist[i].onmouseover=trMouseover;
trlist[i].onmouseout=trMouseout;
}
}
}
function makeDoubleDelegate(function1, function2) {
return function() {
if (function1)
function1();
if (function2)
function2();
}
}
window.onload = makeDoubleDelegate(window.onload, addTrMouseEvents );
last edited on January 29th, 2009 at 1:33 PM
Categories
Comments
- Slashback on "window.onload via double delegate function" - The makeDoubleDelegate() function is rather simple and straightforward, so I find it quite odd that Chrome can't handle it. I do…
- Joaquin Serra on "window.onload via double delegate function" - Hello, i'm using this function one year but i realized now that in Google chrome doesn't work. Have you got some solution?
- tadd on "Javascript function to add css" - thanks for the post
- Slashback on "window.onload via double delegate function" - The makeDoubleDelegate function just needs to be available, so include it once somewhere in your html file or an included javascript…
- Neil Haskins on "window.onload via double delegate function" - I don't understand exactly how this is to be used; I've just used javascript in a cut and paste manner really. Does the whole code go…