Bootstrap add active class to navbar automatically

If you are using bootstrap library's navbar then you may come to a point where you need to automatically set the active page class via class='active' for each page. But if you want this to automatically handled then you can use the following javascript snipt.

    $(document).ready(function() {
        $('a[href="' + this.location.pathname + '"]').parent().addClass('active');

This will solve the problem.

blog comments powered by Disqus

About Me

I am working as freelance system analyst, software architect and programmer. The technologies in which I worked in past are Microsoft .Net, Visual Studio, ASP.Net, C#, VB.Net, VB, C, C++, HTML5, CSS3, Javascript, MS SQL, MySQL, SQLCE, VSS, SVN, GIT, JIRA, FishEYE, Bamboo, Agile Project Management, Project Management and many more.

I am good learner and keep learning new technologies.

I did MSCS and BSCS degrees from University of South Asia.

Month List

Page List

    Recent Comments


    Month List