I have a WordPress based website, and my theme highlights the current menu item by adding "current-menu-item" class to it.
The thing is that I have a menu item with 3 submenu items and all of them point to the same page with different container ids (their href contains container Id), hence all of them are highlighted.
How can I highlight only the menu item which's href points to the currently viewed container?
<ul>
<li><ahref="URL/who-we-are/"><span>WhoWeAre</span></a>
<ul>
<li id="first"><ahref="URL/who-we-are/#wherewework"><span>WhereWeWork</span></a></li>
<li id="second"><ahref="URL/who-we-are/#whatwebelieve"><span>WhatWeBelieve</span></a></li>
<li id="third"><ahref="URL/who-we-are/#ourpartners"><span>OurPartners</span></a></li>
</ul>
</li>
<li><ahref="#"><span>GetInvolved</span></a>
<ul>
<li><ahref="URL/vacancies/"><span>Vacancies</span></a></li>
<li><ahref="URL/Become-Active/"><span>BecomeActive</span></a></li>
</ul>
</li>
<li><ahref="URL/contactus/"><span>ContactUs</span></a></li>
</ul>
I have tried this answer by inserting the following after tag:
function onVisibilityChange(el, callback) {
var old_visible;
return function () {
var visible = isElementInViewport(el);
if (visible != old_visible) {
old_visible = visible;
if (typeof callback == 'function') {
callback();
}
}
}
}
var handler = onVisibilityChange(#whatwebelieve, function() {
$( "#second" ).removeClass( "current-menu-item" )
});
//jQuery
$(window).on('DOMContentLoaded load resize scroll', handler);