jcadima
10/27/2016 - 3:14 PM

Add jQuery active class to menu item

Add jQuery active class to menu item


http://stackoverflow.com/questions/14607480/jquery-add-active-class-to-main-menu



<ul class="navbar-nav">
			<li><a href="/subscription" class="menu">Subscribe</a></li>
			<li><a href="/about" class="menu">About Us</a></li>
			<li><a href="/gift" class="menu">Gift</a></li>
			<li><a href="/contact" class="menu">Contact</a></li>
			<li><a href="/shop" class="menu">Shop</a></li>
			<li><a href="/faq" class="menu">FAQ</a></li>
</ul>



<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<script>
jQuery(document).ready(function(){
   $("a.menu").each(function(){
       if($(this).attr("href")==window.location.pathname)
         $(this).addClass("active");
     
   });

})  
</script>



.active  {
    font-weight: bold;
    background: #f4b357;
    color: #fff !important;
}