ErikTJ
ErikTJ

Reputation: 2009

Auto expand JQuery nested menu depending on url

I am using this to get a expandable menu in my site

        $(document).ready(function () {                
            $('li.category').addClass('plusimageapply');
            $('li.category').children().addClass('selectedimage');
            $('li.category').children(":not(a)").hide();
            $('li.category').each(
            function (column) {
                $(this).click(function (event) {
                    if (this == event.target) {
                        if ($(this).is('.plusimageapply')) {
                            $(this).children().show(200);
                            $(this).removeClass('plusimageapply');
                            $(this).addClass('minusimageapply');
                        }
                        else {
                            $(this).children(":not(a)").hide(200);
                            $(this).removeClass('minusimageapply');
                            $(this).addClass('plusimageapply');
                        }
                    }
                });
            }
            );
        });

How do i make it auto expand to the current menu? My links is in the format

/Article/Category1/Category3

If i am at this URL I want Category3 expanded which is under Category1. A menu item is in format

<li class="category">
    <a href"/Article/Category1/Category3/">Category3</a>
    <ul> ... [more sub-categories] ... </ul>
</li>

Upvotes: 1

Views: 413

Answers (1)

devmiles.com
devmiles.com

Reputation: 10014

Use window.location.pathname to match it to your menu's links.

See this question to get an idea on how to do that with jQuery:

Use jQuery to match current URL to herf in a UL and add class if matched

Upvotes: 1

Related Questions