Dynamically Add "Active Menu Item" Class - Jquery
<div id="TopMenu"> <ul> <li><a href="index.php">Home</a></li> <li><a href="about.php">About</a></li> <li><a href="contact.php">Contact</a></li> </ul> </div>
<script type="text/javascript"> //<![CDATA[ $(function(){ var currenturl = window.location.pathname, urlRegExp = new RegExp(currenturl.replace(/\/$/,'') + "$"); $('#TopMenu ul li a').each(function(){ if(urlRegExp.test(this.href.replace(/\/$/,''))){ $(this).addClass('menuactive'); } }); }); //]]> </script>
0 comments:
Post a Comment
How can we help? We’ll get back to you within 12 hours.
Feel free to ask,Your feedback is always appreciated...