EDIT: It is working with this code:
<div id="navigation">
<ul class="menu">
<li><a href="/index.php">Home</a></li>
<li><a href="/about">About Me</a></li>
<li><a href="/blog">Blog</a></li>
<li><a href="/projects">Projects</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="/time">Current Time</a></li>
<li><a href="/help">Help Me</a></li>
</ul>
</div>
And the code to make the class active:
<script>
$(function () {
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/\/$/, '') + "$");
$('#navigation a').each(function () {
if (urlRegExp.test(this.href.replace(/\/$/, ''))) {
$(this).addClass('active');
}
});
});
</script>
This is working now, but when i'm going to Site/Projects/Project1
It makes nothing active. And when i go to Site/Project
s it makes the projects tab active.
So it is working, but i also want the projects tab to stay active when i'm on Site/Projects/Project1
Array index starting from zero. But you have started the for loop with count=1. May be that cause the issue. Kindly change the following code and test it out.
for(i=1;i<aObj.length;i++) {
should be
for(i=0;i<=aObj.length;i++) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With