cancel
Showing results for 
Search instead for 
Did you mean: 

How to add top links in active class

How to add top links in active class

How to add active class in tops links.

 

\app\design\frontend\default\default\template\page\template\links.phtml

 

 

http://magento.stackexchange.com/questions/63959/how-to-add-top-links-in-active-class

1 REPLY 1

Re: How to add top links in active class

Add the below code into your links.phtml file from the following path.

 

app\design\frontend\mypackage\mytheme\template\page\template\links.phtml

<script type="text/javascript">

jQuery(function(){

var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/\/$/,'') + "$"); 
// create regexp to match current url pathname and remove trailing slash if present as it could
// collide with the link in navigation in case trailing slash wasn't present there
// now grab every link from the navigation

jQuery('.links a').each(function(){
// and test its normalized href against the url pathname regexp
if(urlRegExp.test(this.href.replace(/\/$/,''))){
jQuery(this).addClass('active');
}
});

});

</script>

 

NOTE: Please change your class name if its different in your code.

 

Hope this helps you.

Query solved? Accept as Solution.Thanks
Eric Baily