Answer the question
In order to leave comments, you need to log in
How to change the background of the active item in the menu?
How to make the background of an item in the menu appear when we are on a particular page. For example, we are on the 'Home', and in the menu the background of the 'Home' has changed. For example, as in the menu of this site.
The active item is the item that points to the page we are on.
P.S. I'm sorry for explaining so badly.
Answer the question
In order to leave comments, you need to log in
It can be implemented in Javascript if it's just layout, without using CMS.
If this is a CMS, then it has an active class on the navigation item related to different pages.
js will look like this
var urlNow = window.location.pathname.split('/').join(' ');
$(".nav a").each(function(){
var hrefLink = $(this).attr('href');
var findConsilience = urlNow.indexOf(hrefLink);
if(findConsilience > 0){
$(this).addClass('item-active');
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question