Use jQuery to select current menu item in css

CSSjQueryMenu SelectedMobile menu

 This tip is great for use with Joomla and mmenu.

@micha149 has shown me this jQuery snippet which will catch all absolute and relative URLs.

var url = window.location.href;  // Will only work if string in href matches with location 
$('.menu a[href="'+ url +'"]').addClass('active'); 
 // Will also work for relative and absolute hrefs

$('.menu a').filter(function() { 
return this.href == url; 
}).addClass('better-active');

 

 

http://www.paulund.co.uk/use-jquery-to-highlight-active-menu-item

Leave a Reply