Wednesday 24 December 2014

How to add active class in anchor tag when page reload?

Put this script at the footer of the page.

<script>
       jQuery(document).ready(function(){
          var currurl=document.location.href;
           jQuery('#company-widget li').each(function(e){
           var href = jQuery(this).find('a').attr('href');
            if(currurl.indexOf(href)>0){
                jQuery(this).find('a').addClass('active');
            }else{
               jQuery(this).find('a').removeClass('active');
           }
      });
 });
</script>

No comments:

Post a Comment