No Caching CSS Selector in Menu
I have a jQuery menu that adds the class selected to links in a menu. The problem is that when you click the back button the class of selected remains on the link you just visited instead of for the link of the page you are actually on.
So far I've tested it only on FF, IE and Chrome. This problem is only encountered on FF. I was wondering if there is a way in jQuery to not cache that class. I know there are ways to not cache the whole page but I don't want to go that route because it slows down the performance of the site and defeats the purpose of caching.
Here is the code:
- // this now runs on document ready...
jQuery(function($){
var pathmatch = location.pathname.match(/([^\/]+)$/);
// set selected by the current pathname, or default to Home...
if( !pathmatch || !$('#menu a[href$="' + pathmatch[1] + '"]').addClass('selected').length){
$('#menu a').eq(0).addClass('selected');
}
$('#menu a')
.hover(function(ev){
// add (or remove) 'hovering' class to the parent LI and its parent UL...
$(this).parent().parent().andSelf().toggleClass('hovering',ev.type==='mouseenter');
})
});