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'); } });
Please support us, Like us on Facebook.
Subscribe to:
Post Comments (Atom)
it is not working
ReplyDeleteIt is working Gokulan. Make sure there is jquery library added in your page. If not than add following javascript in your page.
Deletehttp://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
thanks it works for me
ReplyDelete