I posted on the duplicate of this, so I'll try here to :)

Is there any particular reason you need JavaScript to do this,
instead
of just using CSS?
#menu ul {
        display:none;
}

body#foo ul.foo, body#bar ul.bar, body#foobar ul.foobar {
        display:block;
}

Waiting until domready to hide the uls means they will show initially,
perhaps long enough for the user to see. Hiding and showing with CSS
alleviates that problem.

On Apr 18, 11:33 pm, Chuck Harmston <cpharms...@gmail.com> wrote:
> Hi Matt,
> Give this a shot:
>
> $(document).ready( function(){
>          $( '#menu ul' ).hide();
>          $( '#menu li.' + $( 'body' ).attr( 'id' ) + ' ul' ).show();
>
> });
>
> Demo here:http://jsbin.com/ehape
>
> Chuck Harmstonhttp://chuckharmston.com
>
> On Sat, Apr 18, 2009 at 10:50 AM, Max <mackerma...@gmail.com> wrote:
>
> > hi Im new to jquery and having some trouble adapting the code below.
> > the function is for a accordion menu. I want it to recognize the
> > body's id, and show the sub menu who's class matches the body id.
> > right now it is set to show the submenu with class="test".
>
> > function initMenu() {
>
> > $('#menu ul').hide();
> > $('#menu ul.test').show();
> > $('#menu li a').click(
> > function() {
> > $(this).next().toggle();
> > }
> > );
> > }
> > $(document).ready(function() {initMenu();});
>
> > do i start with something allong the lines of
> > var bodyid = $("body").attr("id");
> > ?
>
> > Any suggestions greatly appreciated.
>
> > Thanks
> > -Max

Reply via email to