Auto Selecting Navigation
Hello all, and thanks for making this forum 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-S ... Navigation
But I am not able to make it work at all.
Here is my HTML:
-
<ul id="mainNav">
<li><a href="/product"><span>Product</span></a></li>
<li><a href="/blog"><span>News & Events</span></a></li>
<li><a href="/support"><span>Support</span></a></li>
<li><a href="/locator"><span>Dealer Locator</span></a></li>
<li><a href="/about-2xl"><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');
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