kalponikoronno

Jquery active highlight menu

Aug 25th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2.     var str=location.href.toLowerCase();
  3.     $(".nav li a").each(function() {
  4.         if (str.indexOf(this.href.toLowerCase()) > -1) {
  5.             $(".nav li.current-page").removeClass("current-page");
  6.             $(this).parent().addClass("current-page"); /*your changing class name; such as 'active'*/
  7.         }
  8.     });
  9. })
  10.  
  11. /*
  12. <ul class="nav">
  13.     <li class="current-page"><a href="#"></i>Home</a></li>
  14.    
  15.     <li><a href="#"></i>Sample Page</a></li>
  16.    
  17.     <li><a href="#"></i>About Us</a></li>
  18. </ul>  
  19. */
  20. //source page: http://blog.huidesign.com/automatically-highlight-current-page-in-navigation-with-css-jquery/
Advertisement
Add Comment
Please, Sign In to add comment