Auto-Selecting Navigation works for active page but how to add class to parent menu items?
Posted
by jacqueschoquette
on Stack Overflow
See other posts from Stack Overflow
or by jacqueschoquette
Published on 2010-05-01T22:28:11Z
Indexed on
2010/05/01
22:37 UTC
Read the original article
Hit count: 137
jQuery
|navigation
I am following this article http://docs.jquery.com/Tutorials:Auto-Selecting_Navigation
I am able to successfully add a class to the active page li menu item but does anyone know how to modify or add to this script so that any parent menu li items also get the active class?
I would like to avoid having to add ID's as the menu items will be changing alot
My menus have three levels max
here is the script jquery script i am using
$(function(){ var path = location.pathname.substring(1); if ( path ) $('.topLevel a[href$="' + path + '"]').attr('class', 'underline'); });
which works on the current page li a
I thought I could go this route
$('.topLevel a[href$="' + path + '"]').attr('class', 'underline').parent().attr('class', 'underline');
but it does not seem to work any ideas?
a working example can be found here
whistlerwebandprint.com/home.html
© Stack Overflow or respective owner