How to keep the current accordion menu active on page reload by Jquery

HTML==>

<nav id="sidebar">
   
         <ul class="list-unstyled components nav">
            
            <li><a href="about-project.jsp"><i class="glyphicon glyphicon-briefcase"></i>About project</a></li>
            <li><a href="orgchart.jsp"><i class="fa fa-sitemap" aria-hidden="true"></i>Organisation chart</a></li>
            <li><a href="profiledata"><i class="fa fa-users"></i>Prosecutor's
               Profile</a>
            </li>
            <li><a href="links.jsp"><i class="fa fa-link" aria-hidden="true"></i> Link Portal</a></li>
            <li><a href="contact.jsp"><i class="fa fa-phone"></i>Contact Info</a>
            </li>
         </ul>
     
  

</nav>

Script==>

<script> 
$(window).on('load',function(){
var addr1 =$(location).attr('href');
      var  parts = addr1.split("/");
      var last_part = parts[parts.length-1].trim();            
      
    $("nav#sidebar ul li a").each(function(){
    if(last_part==$(this).attr('href').trim()){
    $(this).css({"color": "#000","background" : "#fff"});   
   
    }
    else{
}
});

});

</script>

Comments

Popular posts from this blog

datatable with both top and bottom scroll bar.

Display Loader and disable page while waiting for ajax request

Remove GIT integration from VSCode