K
K
kid-programmer2014-07-27 16:36:00
ASP.NET
kid-programmer, 2014-07-27 16:36:00

How to make an active link in the main menu?

Please tell me how you do the following:
There is a main menu for example: News, Blogs, Contacts... when you click on these links, pages open and this link changes (color, background, any other style). How to pass the name of the class or menu item that needs to change the css style. How do you do it?
PS Using asp.net mvc

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
ZhigulskiyNikolay, 2014-07-27
@kid-programmer

If I understand correctly, you want to change the css class of the link leading to the page the user is currently on.
I do it with javascript and jquery this way:

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question