several things might help: 1) the use of "@" is deprecated within selectors. Tutorial was likely written prior to jQuery 1.3 try: $(function(){ var path = location.pathname.substring(1); if ( path ) $('#sidebar_content a[href$="' + path + '"]').addClass( 'selected'); // used addClass instead of example in case other styling class already exists }); 2) you weren't showing the $(function() or $(document).ready(function(). Be sure your jQuery is wrapped in one of these functions fx wrote: Hello all, and thanks for making this available. I am trying to add a class to my menu for the page it is currently on. I followed this example: http://docs.jquery.com/Tutorials:Auto-Selecting_NavigationBut I am not able to make it work at all. Here is my HTML: ------------------------------------------------------------ <ul id="mainNav"> <li><a href=""><span>Product</span></a></li> <li><a href=""><span>News & Events</span></a></li> <li><a href=""><span>Support</span></a></li> <li><a href=""><span>Dealer Locator</span></a></li> <li><a href=""><span>About</span></a></li> </ul> ------------------------------------------------------------ To make the nav element highlighted, the list item must have a class of 'hover' like this '<li class="hover">...' And here is my jQuery: ------------------------------------------------------------ var path = location.pathname.substring(1); if ( path ) $('#mainNav a...@href$="' + path + '"]').parent().attr('class', 'hover'); ------------------------------------------------------------ For the page /support for example, alert(path) would say 'support'. The script is not applying any CSS to the list elements. I tried different combinations, tried to add a class to the a element by removing parent(), but nothing is triggering. Please help. Thanks, Francois |
- [jQuery] Auto Selecting Navigation fx
- [jQuery] Re: Auto Selecting Navigation Charlie