How to change active class while click to another link in bootstrap use jquery?

前端 未结 13 1231
刺人心
刺人心 2020-11-30 05:32

I have a html as sidebar, and use Bootstrap.

13条回答
  •  独厮守ぢ
    2020-11-30 05:51

    This will do the trick

     $(document).ready(function () {
            var url = window.location;
            var element = $('ul.nav a').filter(function() {
                return this.href == url || url.href.indexOf(this.href) == 0;
            }).addClass('active').parent().parent().addClass('in').parent();
            if (element.is('li')) {
                element.addClass('active');
            }
        });
    

提交回复
热议问题