I've created a navigation structure as follows:
<ul class="page-sidebar-menu">
<li class="menu">
<a href="">
<span class="title">Menu Item</span>
<span class="arrow"></span>
</a>
<ul class="sub-menu">
<li>
<a href="somehref">Sub Menu Item</a>
</li>
</ul>
</li>
</ul>
In order to highlight the submenu link, I need to add an active class to '.submenu li'. Additionally, I want to add an active class to 'li.menu' based on the href of '.submenu li a'. I attempted to achieve this with the following code, but it's not functioning properly:
$(function(){
var current = location.pathname;
current = current.substring(current.lastIndexOf('/'));
$('.sub-menu li a').each(function(){
var $this = $(this);
if($this.attr('href').indexOf(current) !== -1){
$('.sub-menu:parent').addClass('start active open'); //ISSUE
$('.sub-menu li a:parent').addClass('active');
}
});