After creating an unordered list item with Html.ActionLink
, which renders as an anchor tag, I successfully applied CSS for hover effects. However, I am facing an issue where the li
box should be highlighted when clicked. Despite using jQuery, the class does not seem to get applied as expected. There are no errors in the debugger tools, so it's unclear what the problem may be. Below is the snippet of my code:
$(document).ready(function() {
$('#navcontainer ul li a').click(function() {
$('.highlightMenu').removeClass('highlightMenu');
$(this).addClass('highlightMenu');
});
});
#navcontainer ul {
display: block;
list-style-type: disc;
padding-top: 40px;
}
#navcontainer ul li {
display: inline-block;
border: 5px solid #009ddc;
background: #fff;
color: #24387f !important;
}
#navcontainer li a:hover {
color: #fff !important;
background-color: #009ddc;
}
#navcontainer ul li a {
text-decoration: none;
padding: .2em 3em 1em 1em;
color: #24387f !important;
font-size: larger;
font-weight: bold;
}
.highlightMenu {
color: #fff !important;
background-color: #009ddc;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="navcontainer">
<ul class="nav navbar-nav navbar-left text-center">
<li>@Html.ActionLink("Team Management", "Team", "Admin", null, null)</li>
<li>@Html.ActionLink("User Management", "UserProfile", "Admin", null, null)</li>
</ul>
</div>