:hover Pseudo Class Bug Fix for IE6

July 5, 2007 | Filed Under Code Snippets, Web Design by Robert

For those of you familiar with the :hover pseudo class, you probably know that IE6 and below is not.

A simple example of the :hover pseudo class in action is when you mouse over a Hyperlink and it changes color, or it becomes underlined or something dazzling like that. A more advanced example is applying :hover to other tags such as a <td> to make the data cell of a table change color, this is the example I’m going to talk about today.

To get this working in IE6 I have gone through a large amount of resources with javascript fixes, that work—but can be overly complicated. I have also attempted to use some .htc behavior fixes, which can be incredibly finicky and are also invalid CSS according to W3 standards.

But don’t worry! There is hope! Finally after wrestling with this issue for a long time and doing some good investigating for a decent fix, I found it through the use of jQuery.

The Script:

<script src="/include/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
        $('#my-calendar td').hover(function(){
               $(this).addClass('over');
        }, function() {
               $(this).removeClass('over');
        });
});
</script>

The CSS:

.over {background-color: #ffff00;}

The HTML:

<table id="my-calendar">
    <tr>
        <td>hover over me!</td>
    </tr>
</table>

Basically—similar to some JavaScript examples you may have seen jQuery uses a mouseover (hover) and adds the “over” class to your <td>. Likewise—when you mouse out it simply removes the class. It’s that simple and it actually works!

View the Example
Download JQuery

Bookmark and Share

7 Responses to “:hover Pseudo Class Bug Fix for IE6”

  1. August 6th, 2007
    ethan Andrews Says:

    thank you! I too have been looking for a good solution to this problem, you rock.

  2. February 20th, 2008
    Livingston Samuel Says:

    Similar to your script I’ve come with a general idea that will help in implementing the hover function for non-anchor elements in IE6. you can find it here

    Hover for non-anchor elements in IE6

  3. February 21st, 2008
    rafik Says:

    excellent; nice job, well done

  4. December 22nd, 2008
    gaurav Says:

    nice job ..thanks a lot..was Cursing the IE ..jQuery as always rocks

  5. September 10th, 2009
    sandrar Says:

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  6. April 29th, 2010
    Livingston Samuel Says:

    Here is a better performing solution for the IE6 hover issue, http://blog.delivi.com/javascript/updated-hover-for-non-anchor-elements-in-ie6/

  7. August 18th, 2010
    Pierre Maoui Says:

    I have worked for a complete solution which has been released. It’s a plugin of 1.6kb that you can find on the official Jquery website:
    http://plugins.jquery.com/project/ie6hover

    You don’t have to modify even one line of your code, just loading the plugin, that’s all.


Leave a Reply