I'm encountering an issue with the following code:
JavaScript
$(document).ready(function() {
var url = window.location;
var element = $('#nav1 li a').filter(function() {
return this.href == url || url.href.indexOf(this.href) == 0;
}).parent().addClass('navigation__active');
if (element.is('li')) {
element.addClass('navigation__active').parent().parent('li').addClass('navigation__active')
}
});
HTML
<ul id="nav1" class="navigation">
<li class="navigation__active"><a href="#"><i class="zmdi zmdi-home"></i>
Home</a></li>
<li class="navigation__sub">
<a href="#"><i class="zmdi zmdi-view-week"></i> About</a>
<ul>
<li><a href="#">History</a></li>
<li><a href="#">Team</a></li>
<li><a href="#">Projects</a></li>
</ul>
</li>
<li class="navigation__active"><a href="#"><i class="zmdi zmdi-home"></i>
Contact</a></li>
<ul>
I have successfully implemented the functionality to select items under About like History, Team, Projects. However, I am facing a problem where the navigation__active class is not being applied when clicking on Home or Contact. Is there a solution for this?