Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design
Showing posts with label Add active class. Show all posts
Showing posts with label Add active class. Show all posts

How to add active class to menu or li after form load using jQuery

If you want to make menu active using jQuery after form load use my following code. You can also use this code if you have ul/ li and want to add active class to selected li.

<ul>
  <li><a href="https://www.blogger.com/page1.php">page 1</a></li>
  <li><a href="https://www.blogger.com/page2.php">page 2</a></li>
</ul>


$('li').each(function(){
    if(window.location.href.indexOf($(this).find('a:first').attr('href'))>-1)
    {
    $(this).addClass('active').siblings().removeClass('active');
    }
});

 

Copyright @ 2017 HKBlog.