Right. All your anchors have href's - do these go anywhere? If they do (and they're not just bookmarks) then what's the point of showing/hiding anything? If they don't then why are they there?
Reason for asking is that unless you really, really want or need those anchors you could simplify your html (and script a little bit) by removing them and setting a click on the list item. Then your use of 'child' is accurate because the ul would actually be a child of the clicked element, whereas at the moment the ul is _not_ a 'child' of the anchor. Example using current html (as provided in previous post)... $('#control a').click(function(){ var list = $(this).next(); if(list.is(':visible')){ list.hide(); }else{ $ (this).parent().siblings().find('ul:visible').add(list[0]).toggle(); // or $('#control ul:visible').add(list[0]).toggle(); if not multi-levelled // or $(this).parent().siblings().find('ul:visible').hide(); list.show(); // or ... etc, etc } return false; }); Example using simplified html (squished for space!)... <ul id="control"> <li>A <ul><li>AAAAA</li></ul> </li> <li>B <ul><li>BBBBB</li></ul> </li> <li>C <ul><li>CCCCC</li></ul> </li> <li>D <ul><li>DDDDD</li></ul> </li> </ul> $('#control li').click(function(){ var list = $('ul', this); if(list.is(':visible')){ list.hide(); }else{ $(this).siblings().find('ul:visible').add(list[0]).toggle(); } return false; }); These are simply examples and there are other permutations of jQuery calls. The main point is that you don't really need to store anything; jQuery can be used to hide/show all the necessary at the time of the click. HTH On Nov 21, 4:56 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Thanks for asking, let me try and clear up some of your questions. > > The DOM looks something like this: > > <ul id="control"> > <li><a href="A">A</a> > <ul> > <li>AAAAA</li> > </ul> > </li> > <li><a href="B">B</a> > <ul> > <li>BBBBB</li> > </ul> > </li> > <li><a href="C">C</a> > <ul> > <li>CCCCC</li> > </ul> > </li> > <li><a href="D">D</a> > <ul> > <li>DDDDD</li> > </ul> > </li> > </ul> > > - Onload all nested ULs (withing #control) are hidden > - On first click, first child of the <a> is :visible > - On Second click: > - Was the second click the same as the first click? > - Yes: Toggle closed the child UL > - No: Close anything open (there should only be 1 open at anytime), > then open the corresponding child UL > > So like I stated earlier I guess where I'm stumbling is on how to > collect and check back and know what was actually clicked, and how to > keep checking agaisnt it in the future. > > Hope that clears things up. :) > > David > > On Nov 20, 5:19 pm, Wizzud <[EMAIL PROTECTED]> wrote: > > > Some questions: > > > What happens on the first click? Nothing, or "Hide child ul"? > > What happens on the third, fourth, nth, clicks? Does any one click > > always check against the preceding click, regardless of whether that > > preceding click matched it's own preceding click or not? > > Are you always checking nth click against (n-1)th click? Or, if you > > get a match [ nth = (n-1)th ] are you clearing down your 'clicks > > stack' and starting again from 'first' click? > > What is 'child ul' a child of? The preceding [ (n-1)th ] clicked > > element? Or does it depend on whether nth = (n-1)th? > > > On Nov 20, 6:22 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > > Hello everyone, > > > > Just started working with jQuery in the past few weeks, fairly > > > impressed thus far. :) > > > > I've got a questions which actually might touch base more on a general > > > JS question but figured might as well ask it. > > > > What I'm trying to do: > > > > // What got clicked first? (capture) > > > // What was clicked Second? (capture) > > > // Was the second click the same as the first? > > > // Hide child ul > > > // else > > > // Hide child ul + open new child from second parent > > > > I guess my key stumbling block is storing the last clicked element > > > into memory to check agaist during the next function call. > > > > I've this so far: > > > var $whatClicked = ($(this).get()); > > > > Any help is greatly appreciated. > > > > Cheers, > > > David