Posted By

humanoid on 02/25/10


Tagged

navigation jquery highliting


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

bostonbasso


add class to highlight navigation item if page url


 / Published in: jQuery
 

  1. <script type="text/javascript">
  2. $(function(){
  3. $page = location.pathname;
  4. if(!$page) {
  5. $page = 'index.html';
  6. }
  7. $('ul.navigation li a').each(function(){
  8. var $href = $(this).attr('href');
  9. if ( ($href == $page) || ($href == '') ) {
  10. $(this).addClass('on');
  11. } else {
  12. $(this).removeClass('on');
  13. }
  14. });
  15. });
  16. </script>

Report this snippet  

You need to login to post a comment.