If you have control on the HTML, it would be a LOT easier/cleaner/make- more-sense if you separate classes
for instance <li class="nav_sub_default"></li> <li class="nav_sub_company"></li> <li class="nav_sub_products"></li> .... to <li class="nav_sub default"></li> <li class="nav_sub company"></li> <li class="nav_sub products"></li> .... That would make your jQuery life much easier, plus it makes the items actually have "common" class characteristics Now when you want to manipulate them all: $("li.nav_sub").doSomejQueryAction and yet they all still have their unique styles/characteristics On Jan 13, 12:01 pm, "Diane Nardozzi" <diane...@gmail.com> wrote: > You could add the offscreen class to the appropriate menu item and then > remove the sibling classes all at once > $(.nav_sub_products).siblings().removeClass('onscreen'); You would just have > to be sure that all the menu items are true siblings. > > On Tue, Jan 13, 2009 at 11:36 AM, r...@lighthouseuk.net > <r...@50-tuning.com>wrote: > > > > > Hi, > > I'm new to jQuery and liking what I've seen so far. > > > I'm curious as to whether I can reduce my code, using chaining > > perhaps? > > > Example... > > > $('.nav_company').hoverIntent(function() { // toggle display of > > company sub menu content panel > > $('.nav_sub_default').removeClass('onscreen').addClass > > ('offscreen'); > > $('.nav_sub_company').removeClass('offscreen').addClass > > ('onscreen'); > > $('.nav_sub_products').removeClass('onscreen').addClass > > ('offscreen'); > > $('.nav_sub_markets').removeClass('onscreen').addClass > > ('offscreen'); > > $('.nav_sub_tools_support').removeClass('onscreen').addClass > > ('offscreen'); > > $('.nav_sub_news_events').removeClass('onscreen').addClass > > ('offscreen'); > > },function(){ > > return false; > > }); > > > Based on the fact that there are 6 menu items (nav_sub_x) - I > > currently have the above code entered 6 times to add and remove the > > necessary classes from each of the relevant DIVs on the page. > > > Is there a cleaner way to do this? > > Many thanks in advance. > > Cheers, > > Rob