[jQuery] Re: Select nested ul inside a li element

2008-11-06 Thread Rik Lomas

Hi,

The ul is inside the li, not the next element, so you can do
$(this).find('ul') to select it

Rik

2008/11/6 suntrop [EMAIL PROTECTED]:

 Hi. I want to collapse my navigation. But I can't select the nested
 ul inside a li
 The markup:
 ul id=navigation
liFruits
   ul
  liApples/li
  liBananas/li
  liStrawberries/li
   /ul
 /li
 liVegetables
ul
  liTomatoes/li
  liPeas/li
   /ul
 /li

 This is what I tried to do:
 $('#navigation li').click(function() {
$(this).next().slideToggle(fast);
});

 But this code doesn't collapse the nested ul but the next li. When I
 click Fruits it'll toggle Vegetables.
 How can I select just the ul inside the li? When I click Fruits it
 should toggle the ul with Apples, Bananas ...

 This one won't work either:
 $('#navigation li').click(function() {
$(this ' ul').slideToggle(fast);
});
 or this:
 $('#navigation li').click(function() {
$(this).child().slideToggle(fast);
});

 Hope somebody can help. Thanks!



-- 
Rik Lomas
http://rikrikrik.com


[jQuery] Re: Select nested ul inside a li element

2008-11-06 Thread Richard D. Worth
Or in case there are even more levels

$(this).children('ul')

- Richard

On Thu, Nov 6, 2008 at 9:04 AM, Rik Lomas [EMAIL PROTECTED] wrote:


 Hi,

 The ul is inside the li, not the next element, so you can do
 $(this).find('ul') to select it

 Rik

 2008/11/6 suntrop [EMAIL PROTECTED]:
 
  Hi. I want to collapse my navigation. But I can't select the nested
  ul inside a li
  The markup:
  ul id=navigation
 liFruits
ul
   liApples/li
   liBananas/li
   liStrawberries/li
/ul
  /li
  liVegetables
 ul
   liTomatoes/li
   liPeas/li
/ul
  /li
 
  This is what I tried to do:
  $('#navigation li').click(function() {
 $(this).next().slideToggle(fast);
 });
 
  But this code doesn't collapse the nested ul but the next li. When I
  click Fruits it'll toggle Vegetables.
  How can I select just the ul inside the li? When I click Fruits it
  should toggle the ul with Apples, Bananas ...
 
  This one won't work either:
  $('#navigation li').click(function() {
 $(this ' ul').slideToggle(fast);
 });
  or this:
  $('#navigation li').click(function() {
 $(this).child().slideToggle(fast);
 });
 
  Hope somebody can help. Thanks!



 --
 Rik Lomas
 http://rikrikrik.com



[jQuery] Re: Select nested ul inside a li element

2008-11-06 Thread suntrop

This is cool! The find-thing works exactly like I want it :-)

Unfortunately the box collapses even if I click on a link (Apples).
Of course, it's in the li as well. Can I disable that?


Thanks for your answers guys!