treehouse : what would you like to learn today?
Web Design Web Development iOS Development

hide submenu onload

  • Hello!

    I inherited an accordion style menu and can't quite figure out how to make it all collapsed on load.

    Please see http://www.siphon-marketing.com/unifirst/V3/level2.html and you'll notice the menu on the left.

    I'm used to working with menus and accordions in the typical ul/li format and this one has got me stumped!

    Can anybody help me out?

    Len

  • hmmm, that is some heavy javascript there, WAY more work than it needs to be...

    but there is a function available you can call:

    leftnavMenu.prototype.collapseAll = function() {
        for (var i = 0; i < this.submenus.length; i++)
            if (this.submenus[i].className != "collapsed")
        this.collapseMenu(this.submenus[i]);
    };

    In the HTML file at the top you should be able to find this:

    var myMenu;
    window.onload = function() {
    myMenu = new leftnavMenu("my_menu");
    myMenu.init();
    };

    After the line

    myMenu.init();

    add this line:

    myMenu.collapseAll();

    that should work...else, you could do:

    body onload="myMenu.collapseAll();"
    
  • Heya!

    This worked perfectly in Firefox but, unfortunately, not IE! Any ideas?

    By the way...I've moved the page to http://www.siphon-marketing.com/unifirst/V3/level2.html