Tuesday, June 24, 2014

Change the color of the menu item which is selected currently

<div id="menuDiv">
        <ul>
               <li><a href="/site/index">Home</a></li>
               <li><a href="/site/gallery">Gallery</a></li>
        </ul>
</div>

<style>
       
#menuDiv ul li a.active{
              color: yellow;
        }

</style>


<script type="text/javascript">
  $(fu
nction (){
      var phpPath="<?php echo $_SERVER['REQUEST_URI'] ?>";
      $('#menuDiv ul li a').each(function(){
          var url = $(this).attr('href');
          if(url == phpPath){
              $(this).addClass('active');
          };
       });
  });

</script>

No comments:

Post a Comment