I am using jquery lava lamp menu. I want to add current class on li tag not a tag
this is my menu
<div>
<ul class="lavaLamp">
<li><a href="index.php">Home</a></li>
<li><a href="about.php">About</a></li>
<li><a href="contact.php?page=contact">Contact</a></li>
</ul>
</div>
I have tried this.
$(function(){
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/\/$/,'') + "$");
$('.lavaLamp li a').each(function(){
if(urlRegExp.test(this.href.replace(/\/$/,''))){
$(this).addClass('current');
}
});
});
I have tried every thing found on web but nothing works for me. I dont know why all codes not working. I have extra subfolder my URL looks like this:
http://example.com/mysite/index.php
http://example.com/mysite/about.php
Your regex doesn’t seem to work. Anyway, here’s a solution:
Note that I use .parent() to get li element, since you wrote you want to add .current to li, not a.