I want to make a menu, and change the class of parent li
and child li
when clicking.
When I click on the li
with no class="active"
, I want jQuery to add a class on the empty li
and its child li
and remove it from the others li
.
I tried following script but it didn't work for me:
$('.menu .list li > ul > li > a').click(function () {
$('li').removeClass();
$(this).parent().addClass('active');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="menu">
<ul class="list">
<li class="active">
<a href="/Employee/Profile">
<i class="material-icons">person</i>
<span>Profile</span>
</a>
</li>
<li>
<a href="javascript:void(0);" class="menu-toggle">
<i class="material-icons">subject</i>
<span>Leaves</span>
</a>
<ul class="ml-menu">
<li>
<a href="/Admin/AllEmployees">Show My Leaves</a>
</li>
<li>
<a href="/Leaves/RequestForLeave">Request for Leave</a>
</li>
</ul>
</li>
</ul>
</div>
Please help me to write the script.