Hi there,
I have been trying to figure this one out for over an hour but couldn’t. My code works when you highlight a top menu item such as ‘Viesnage’ but there is also a drop-down menu. When a page from drop-down menu is opened which is a sub-category, I want to highlight an appropriate category. So let’s say when I press on ‘Hostels’, I want ‘Viesnage’ to be highlighted.
I have a menu which looks like this:
<ul class="mainNav">
<li class="tab"><a href="http://kurvarom.local/vietos/viesnage" class="tabAnchor">Viesnage</a></a>
<div class="dropdown">
<div class="col">
<ul>
<li><a href="http://kurvarom.local/vietos/viesnage/viesbuciai">Viesbuciai</a></li>
<li><a href="http://kurvarom.local/vietos/viesnage/hosteliai">Hosteliai</a></li>
</ul>
</div>
</div>
</li>
</ul>
I use such jQuery to highlight list items:
var str=location.href.toLowerCase();
$(".mainNav li a").each(function() {
if (str.indexOf(this.href.toLowerCase()) > -1) {
$("li a.current").removeClass("current");
$(this).addClass("current");
$(this).parents("a.tabAnchor").addClass("current"); // I EXPECTED THIS TO WORK BUT IT DOES NOT
}
});