Monday, October 27, 2008

Using jQuery to make LI elements hover-able in IE6

Another necessary hack, this time to overcome IE6's non-support of the hover pseudo-class for LI elements.

This is to be used in situations where navigation is structured using UL, LI, and A elements and styled via CSS.  Please note that additional selectors will be required when implementing this solution: the standard selector (using li:hover notation) and the alternate selector (using li.over notation to support what this JavaScript is accomplishing):

$(document).ready(function() {
// Hack to make li's 'hover-able'
if (document.all && document.getElementById) {
$("#mainnav > .menu ul > li").each(function() {
this.onmouseover = function() { this.className += " over"; }
this.onmouseout = function() { this.className = this.className.replace(" over", ""); }

IE6 PNG alpha transparency solution

I know a bazillion solutions have been posted to the interwebs to solve this problem, but I wanted to make a note of one that I found to work quite well: