[jQuery] Re: Auto Selecting Navigation

2009-09-13 Thread Charlie





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_Navigation

But I am not able to make it work at all.

Here is my HTML:

ul id="mainNav"
lia href=""spanProduct/span/a/li
lia href=""spanNews amp; Events/span/a/li
lia href=""spanSupport/span/a/li
lia href=""spanDealer Locator/span/a/li
lia href=""spanAbout/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] Re: Auto Selecting Navigation

2009-09-13 Thread fx

You did it! Thank you.