Dynamically adding events

    Date: 02/28/08 (Javascript Community)    Keywords: java, seo

    I'm having trouble dynamically adding events to elements in Internet Explorer 6.0.

    The following works like a charm in Firefox, but does absolutely nothing in IE. And by nothing, I mean nuh-thing. Not even a javascript warning:

    document.getElementsByClassName = function(cl) {
        var retnode = [];
        var myclass = new RegExp('\\b'+cl+'\\b');
        var elem = this.getElementsByTagName('*');
        for (var i = 0; i < elem.length; i++) {
            var classes = elem[i].className;
            if (myclass.test(classes)) retnode.push(elem[i]);
        }
        return retnode;
    }
    
    function show_date() {
        this.childNodes[1].style.display = "inline";
    }
    
    function hide_date() {
        this.childNodes[1].style.display = "none";
    }
    
    function add_function() {
        var grid = document.getElementsByClassName('date');
      
        for (var i = 0; i < grid.length; i++) {
            if (window.addEventListener) {
                grid[i].addEventListener("mouseover",show_date, false);
                grid[i].addEventListener("mouseout",hide_date, false);
            } else {
                grid[i].attachEvent("mouseover",show_date, false);
                grid[i].attachEvent("mouseout",hide_date, false);
            }
        }
    }

    Any thoughts?

    Source: http://community.livejournal.com/javascript/150958.html

« I've learned something... || Extending the Date Object »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home