Lexa Vissers
Lexa Vissers

Reputation: 1

remember menu state vertical multilevel navigation

I've tried to make a vertical multilevel navigation, but I can't seem to intergrate a code in order to make the last menu state be remembered when a new page is loaded.

I've searched for options using hash location, and I tried using cookies, I just don't know how to include it into my excisting code.

Well, I would like some help with this. You can see the menu here: http://blendit3d.nl/index_animatie.html

Thnx Sandra

$(document).ready(function() {
            $('.sub').hide();
            $('.nav > li > a').click(function(e) {
                // if new link is opened:
                //function setCookie (GetElementById){
                //    document.cookie = cname + "=" + cvalue + "; " + expires;
                //}


                e.preventDefault();
                $('.sub:visible').slideUp('slow');
                $('.subsub').hide();
                $('.open').removeClass('open');
                $(this).parent().addClass('open').next().slideDown(400).not(':animated');
                return false;
            });

                $('.subsub').hide();
                $('.sub li a').click(function() {
                    $('.subsub:visible').slideUp('300');
                    $('.opensub').removeClass('opensub');
                    $(this).parent().addClass('opensub').next().slideDown('slow');
                    return false;
                });

        });

Upvotes: 0

Views: 238

Answers (1)

Rahul
Rahul

Reputation: 5774

Something like this should help -

For absolute URL only - What this does is it gets current url and match it with the menu markup and adds active class..

$(function(){ 
        // Get current url
        // Select an a element that has the matching href and apply a class of 'active'. Also prepend a - to the content of the link
        var url = window.location.href;
        $('.menu a[href="'+url+'"]').addClass('current_page_item');
});

For Relative URL - This code should work for relative URLs as well. I would recommend you to use this code.

$(function(){ 
   var url = window.location.href;

   $('.menu a').filter(function() {
       return (url.indexOf(this.href) > -1)
   }).addClass('.active');
});

Upvotes: 1

Related Questions