menuitem - Jquery addClass to multiple li -


i have main navigation structure below:

<li>     <a class="dropdown-toggle" href="about">         <?php echo nav_about ?>     </a>     <ul class="dropdown-menu">         <li>             <a href="<?php echo baseurl ?>/about-us.html">                 <?php echo nav_about_profile ?>             </a>         </li>         <li>             <a href="<?php echo baseurl ?>/committee.html">                 <?php echo nav_about_committee ?>             </a>         </li>     </ul> </li> 

and highlight script respective item while url , link matches up:

/* highlight nav menu */ $(function(){     $('#topmain.nav-pills li a').each(function(index) {         if($.trim(this.href) == stripquerystringandhashfrompath(window.location.href)) {             $(this).closest('li').addclass('active');         }     }); });  function stripquerystringandhashfrompath(url) {     return url.split("?")[0].split("#")[0]; } 

i can add active closest hyperlink li, want way add active top li well, result like:

<li class="active"> <-- need class add     <a class="dropdown-toggle" href="about">         <?php echo nav_about ?>     </a>     <ul class="dropdown-menu">         <li class="active">             <a href="<?php echo baseurl ?>/about-us.html">                 <?php echo nav_about_profile ?>             </a>         </li>         <li>             <a href="<?php echo baseurl ?>/committee.html">                 <?php echo nav_about_committee ?>             </a>         </li>     </ul> </li> 

try this:

$('.dropdown-menu li:has(a[href="'+opened_path+'"])').addclass('active') .parent().closest('li') .addclass('active'); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -