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
Just make sure that none of your links have active class to start.
If your nav links are on separate HTML files (like a layout template in express.js that has a menu), you can do this:
$('ul.nav > li > a[href="' + document.location.pathname + '"]').parent().addClass('active');
If they are hashes, do this:
$('ul.nav > li > a[href="' + document.location.hash + '"]').click(function(){ $('ul.nav > li').removeClass('active'); $(this).parent().addClass('active'); });
If you don't want to scroll on hash-click, return false:
$('ul.nav > li > a[href="' + document.location.hash + '"]').click(function(){ $('ul.nav > li').removeClass('active'); $(this).parent().addClass('active'); return false; });