get id of closest ‘ul’ or parent id and get value of ‘href’ attribute with Jquery


//if menu is created dynamically it is very useful
<ul id="slider" style="display: none;">
 <li class="panel cloned">test1</li>
 <li class="panel">
   <h1><a href="/Admin/RoleMaster"> Role Creation </a> </h1>
 <li class="panel cloned">test2</li>


var url = window.location.pathname; //or window.location.toString();

$('#slider li.panel h1 a').each(function(){
   var myHref= $(this).attr('href');
   if( url == myHref) //compare current url with url value

        var ulId = $(this).closest('ul').attr('id'); //get id of ul tag 
        $("#"+ulId).css("display", "block");