Wednesday, 21 August 2013

Menu item addClass disappears when i arrive at new page

Menu item addClass disappears when i arrive at new page

Hi i am using superfish menu, and are relatively new to jquery, when i use
addClass to add a class to a menu item, it adds the class but when the new
page loads it disappears. So to be really clear if i am at the home page
and want to go to the sales page, i would liken the sales menu item to
have the active class when i arrive here is what i have
here is my menu
<div id="navbar">
<ul class="sf-menu sf-js-enabled" id="navmain">
<li><a href="/index.php">HOME</a></li>
<li><a href="/shop/sales/">SALES</a></li>
<li><a href="/shop/clothing/">CLOTHING</a></li>
<li><a href="/shop/accessories/">ACCESSORIES</a></li>
<li><a href="/cart.php">CART</a></li>
<li><a href="/wishlist.php">WISHLIST</a></li>
<li><a href="/contactus.php">CONTACT US</a></li>
<li><a href="/aboutus.php">ABOUT US</a></li>
</ul>
</div>
Here is my jquery
$('#navbar ul li').click(function(){
$('#navbar li a').removeClass("active");
$('#navbar li a').addClass("active");
});
Am i doing this correctly?
I have also tried this to no avail
$('#navbar ul li').click(function(e){
$('#navbar li a').removeClass("active");
$(e.target).addClass("active");
});

No comments:

Post a Comment