Return to Snippet

Revision: 48789
at July 9, 2011 01:23 by iammikecohen


Initial Code
<script type="text/javascript">
        $(document).ready(function(){
            $(".sf-menu li").children("a").each(function() {
                if(window.location.href == $(this).attr('href')){
                    if($(this).parent().hasClass('main_link')){
                        $(this).addClass('active');                        
                    }else{
                        var topLink = $(this).parents('.main_link');
                        topLink.find('a').first().addClass('active')
                    }
                }
            });
        });
    </script>

Initial URL

                                

Initial Description
look through the list items in your main nav and based on href of anchor tags this will set the top level link to have an 'active' class.

Initial Title
Set links with href to current page as active (or if in subnav set their parent to active)

Initial Tags
css, javascript, navigation, jquery

Initial Language
JavaScript