Hi

I have the following snippet to expand/collapse menu items and set the
cookie as well.

    function initMenu() {
  $('#menu ul').hide();
 if ($.cookie('the_cookie')=='a'||$.cookie('the_cookie')=='b'||
$.cookie('the_cookie')=='c'||
        $.cookie('the_cookie')=='d')
  {
      alert('came here with cookie: ' + $.cookie('the_cookie'));
        $("a").filter("." +
$.cookie('the_cookie')).next().slideDown('normal');
      alert('did the sliding: ' + $("a").filter(".b").attr('name'));
  }

  $('#menu li a').click(
    function() {
    $(this).click(function(){setCookie($(this).attr('class'));});
    alert('this isname: ' + $(this).attr('name'));
        $(this).next().slideToggle('normal');
      }
    );
  }
  function setCookie(some)
  {
    $.cookie('the_cookie', some);
    alert('cookie set  ' + some);
  }
  $(document).ready(function() {initMenu();});

as you see. I am trying to set the cookie every time that user clicks
the menu item.  However, the cookie is only being set the SECOND time
user clicks the menu item.
First click - menu item expands
Second click - cookie is set and then menu item collapse.

Why is this? when I have the code inside the click.

I thought maybe becuase i am doing this:
$(this).click(function(){setCookie($(this).attr('class'));});

so just wondering..will it be better if I can just assign a function
to $(this) rather than on 'click'

Thanks

Reply via email to