Reputation: 1227
Here is my code: so, I ran this through debug and it does "remove the "active" class and adds the "active" class to the selected element; however, it does not stay active. This is navigation that is part of the Base.cshtml which is part of the header, I am not sure it it gets reloaded each time, but how do I make the change permanent?
$(document).ready(function(){
var select = '.nav dropdown-container .nav-item';
$(select).click(function() {
$(select).removeClass('active');
$(this).addClass('active');
});
});
Upvotes: 0
Views: 87
Reputation: 86124
When you follow a link, or otherwise perform a navigation event, your entire document is replaced. Nothing in the document is permanent. If you want to simulate permanence, you can use a cookie or localStorage to persist information between requests.
Upvotes: 1
Reputation: 218842
Unless you are loading the new page content with Ajax, It will load the page in a new GET request when you click on the navigational link. That means whatever class you set will not be available.
If you want the active css class to be available for the reloaded page, you should set something on the ViewBag
and use that in the Layout to enable the css class in your navigation links.
Upvotes: 1