I have a sidebar menu which I am using for navigation throughout my website and I am wanting to be able to dynamically add the active class to the appropriate menu item. I've tried using the code bellow but It doesnt seem to be doing anything.
var page = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
$('ul li a[href="'+ page +'"]').parent().addClass('active');
$('ul li a').filter(function() {
return this.href == page;
}).parent().addClass('active');
I might have my syntax wrong for the selector so below I have included a snippet of the sidebar.
<div id="sidebar" class="nav-collapse ">
<ul class="sidebar-menu" id="nav-accordion">
<li>
<a href="dash.php">
<i class="fa fa-dashboard"></i>
<span>Home</span>
</a>
</li>
<li class="sub-menu">
<a href="javascript:;" >
<i class="fa fa-cogs"></i>
<span>Tools</span>
</a>
<ul class="sub">
<li><a href="index.php">Uptime</a></li>
</ul>
</li>
</ul>
</div>