views:

298

answers:

2

Hello,

is there any possible solution, to fadeIn(500) multiple list elements one after the other?

<ul id="list">
 <li>test</li>
 <li>test</li>
 <li>test</li>
 <li>test</li>
 <li>test</li>
</ul>

Kind Regards, Werner

+9  A: 

You could do a recursive function that stops when there's no LI left like this:

function fadeLI(elem) { 
  elem.fadeIn(500, function() { fadeLI($(this).next()); }); 
}                            
fadeLI($("#list li:first")​);​

Check it out here

Nick Craver
+1, yours is better than mine :-)
Andy E
A: 

You want a recursive function to check if there is another li element, and fade it in if so...

function fadeInNext(el){
  if(el.next('li')){
    el.next('li').fadeIn(500,fadeInNext)
  }
}
$('...').fadeIn( 500, fadeInNext )
Andru
This won't work..you're not passing the next element into `fadeInNext`, in either case in jQuery the `if(el.next('li'))` isn't needed...if it doesn't find anything matching the selector, it won't run.
Nick Craver