tags:

views:

37

answers:

1

I have a menu list something like this:

<ul class="submenuList"> 
  <li><a onclick="loadItem('Blue%20Orchid%20Press')" id="Blue%20Orchid%20Press">class="on">Blue Orchid Press</a></li>
  <li><a onclick="loadItem('Brilliant%20Telecommunications')" id="Brilliant%20Telecommunications" class="off">Brilliant Telecommunications</a></li> 
  <li><a onclick="loadItem('CBT%20Systems%201')" id="CBT%20Systems%201" class="off">CBT Systems 1</a></li> 
 </ul>

A currently selected list item has a class = "on". What I want to do is to find the next item in the list after the currently selected one, and set it's class to "on" and trigger it's "onclick", and set the current one to "off".

Any help appreciated!

update:

<div id="menu">
    <div id="main_menu" style="display: block;"><ul><li><a onclick="loadSubMenu('f')" id="f" class="off">featured</a></li><li><a onclick="loadSubMenu('a')" id="a" class="off">advertising</a></li><li><a onclick="loadSubMenu('p')" id="p" class="on">print</a></li><li><a onclick="loadSubMenu('w')" id="w" class="off">web</a></li></ul></div>
    <br clear="all"><hr><br clear="all">
    <div id="sub_menu" style="display: block;"><ul class="submenuList"><li><a onclick="loadItem('Blue%20Orchid%20Press')" id="Blue%20Orchid%20Press" class="on">Blue Orchid Press</a></li><li><a onclick="loadItem('Brilliant%20Telecommunications')" id="Brilliant%20Telecommunications" class="off">Brilliant Telecommunications</a></li><li><a onclick="loadItem('CBT%20Systems%201')" id="CBT%20Systems%201" class="off">CBT Systems 1</a></li><li><a onclick="loadItem('CBT%20Systems%202')" id="CBT%20Systems%202" class="off">CBT Systems 2</a></li></ul></div>
  </div>
+3  A: 

You can do this:

$("#sub_menu .on").removeClass("on").addClass("off").parent("li")
        .next().children("a").addClass("on").click();
Nick Craver
This is what I love about jQuery.
musicfreak
Jonathan
@Jonathan - If you update your question with that HTML, I'll adjust the selector to work.
Nick Craver
I just updated...
Jonathan
@Jonathan - Same, it should only affect `id="sub_menu"` now, see how that works.
Nick Craver
Brilliant! I tried a few things LIKE that, but I must have gotten something wrong. That has been a HUGE help. Thanks so much.
Jonathan
@Jonathan - Welcome! If that answers everything please check the accepted beside the answer so we can cleans up some of the 70,000+ left on the unanswered list :)
Nick Craver
1 down, 69,999 to go!
Jonathan