Get a free trial // Grow your CSS skills // Land your dream job

hide submenu onload

  • # October 4, 2012 at 4:07 pm


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

    Please see 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?


    # October 5, 2012 at 12:05 am

    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.className != "collapsed")

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

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

    After the line


    add this line:


    that should work…else, you could do:

    body onload="myMenu.collapseAll();"
    # October 5, 2012 at 7:41 am


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

    By the way…I’ve moved the page to

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed