§ 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
- Walid on "Adventures with Ubuntu 9.10 on G4 Yikes!" - I am in the same process as you. Although I still dual-boot to Windows for my ganimg leisure. My first contact with Ubuntu was way…
- Slashback on "Simpler adding & removing element classnames" - Actually, the addClassName function does what you want, pretty much the same way you suggest.
- angie on "Simpler adding & removing element classnames" - And what if I want to add a class, but keeping the csseals the element already has?I mean, I have an element with a class, let's name…
- backlinks on "Adjust iframe height to contents" - Definitely helped me.
- Slashback on "Simpler validate form fields are filled in (no additional class names)" - You are welcome!