Featured post

Add active class dynamically in menu and submenu



html:

in html you must have to add below two point.


1) For finding page: <?php $page = 'PAGE NAME'; ?>
2) for add active claass: <?php if($page =='about'){echo 'active';}?>;


Then, this type of menu and dropdown menu or submenu:

<ul class="nav navbar-nav">
    <li class="<?php if($page =='home'){echo 'active';}?>"> href="index.php">Home</li>
    <li class="<?php if($page =='about'){echo 'active';}?>"> href="index.php">about</li>
</ul>
 

After that,

- Add this javascript to submenu page:

<script type="text/javascript">
      $(document).ready(function(){
          $('.dropdown-menu > li.active').parent().parent('li').addClass('active');
      });
 </script>


i'm add this particular subpage, so it easy with submenu and no more complex scipt require.


if you have another smart idea then pls share.

Comments