Bootstrap CSS Active Navigation

前端 未结 13 2376

On the Bootstrap website the subnav matches up with the sections and changes background color as you or scroll to the section. I wanted to create my own menu without all the

13条回答
  •  孤街浪徒
    2020-11-27 12:51

    anyone having problems with this using jsp, watch your packages.

    document.location.pathname gave me: /packagename/index.jsp

    but my href in my navbar called just index.jsp

    So to edit konsumer's answer:

    $(document).ready(function() {
       var string = document.location.pathname.replace('/Package Name/','');
       $('ul.nav > li > a[href="' + string + '"]').parent().addClass('active');
    } );
    

提交回复
热议问题