I have html as a sidebar and use Bootstrap .
<ul class="nav nav-list"> <li class="active"><a href="/">Link 1</a></li> <li><a href="/link2">Link 2</a></li> <li><a href="/link3">Link 3</a></li> </ul>
I want to do something:
When I click link, such as link 3, the page content will change to 3rd level content, and link 3 will have the class active and will remove the active clss in link 1.
I think this can be implemented in jQuery , and I was looking for a lot of questions in SO, for example:
I am using this script:
$(document).ready(function () { $('.nav li').click(function(e) { $('.nav li').removeClass('active'); var $this = $(this); if (!$this.hasClass('active')) { $this.addClass('active'); }
But most of them use preventDefault , this will prevent the continuation of the action. Thus, he cannot go to the content of a page of the 3rd level.
If I remove the preventDefault statement when the page loads Link 3 content, the active class will return to link 1.
So, is there a way to solve this problem?
source share