I need to add active class to the links and change active state while navigating page. I have tried with this but changes not applying after switching between links. (not working after page reload)
Here is my code
$('#shortcuts-main > li').click(function (e) {
$(".shortcut-link-active").removeClass("shortcut-link-active");
$(this).addClass("shortcut-link-active");
});
a{
color:black;
padding-bottom:15px;
display:block;
}
.shortcut-link-active a{
color:red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="shortcuts-main">
<li>
<a href="#">Link 1</a>
</li>
<li>
<a href="#">Link 2</a>
</li>
<li>
<a href="#">Link 3</a>
</li>
<li>
<a href="#">Link 4</a>
</li>
</ul>
Any ideas?