What's the problem? That code looks perfect... have you looked in
Firebug to see where it's adding/removing the class names?
On (unrelated) issue the code might have is the selector you use is
'#nav li a' which will select all of those second level nav elements
too: red/green/black - if that's not intended you could just select
first level elements with:
'#nav > li a' (so only Home/Colours/Contact Me)


On Sep 9, 9:17 pm, John Hanks <[email protected]> wrote:
> Guys, I have a problem with my menu. I am trying to add and remove classes
> when clicking on the main menu links. For instance when on load, the 'Home'
> is the current tab clicked, but when I click on 'Contact Me' I would like
> the class current to be removed from 'Home' and added to 'Contact Me'
> instead.
>
> The code im using is the one below.
>
> Thanks!
>
> <ul id="nav">
>     <li><a class="top current" href="#">Home</a></li>
>     <li><a class="top" href="#">Colours</a>
>         <ul>
>             <li><a  href="#">Red</a></li>
>             <li><a  href="#">Green</a></li>
>             <li><a  href="#">Black</a></li>
>         </ul>
>     </li>
>     <li><a class="top" href="#">Contact Me</a></li>
> </ul>
>
> $("#nav li a").click(function(){
>     $("#nav li a").removeClass("current").addClass("hidden");
>     $(this).addClass("current");
>
> });
>
>

Reply via email to