.until(null / $ ,loopContext)

Description: The end for a repeat loop that finishes if the calling jQuery context is empty.

null / $ – undefined or the jQuery token, optional
If null or missing then the loopContext parameter defaults to false.
If $ is used then loopContext defaults to true.
loopContext – boolean, optional
if true then the current jQuery context starts the next loop iteration. Otherwise the original context from the .repeat() call is used for each iteration.

Tip: For short code use .until($) instead of .until(null,true),
and .until() instead of .until($,false).


Examples with empty-checking loop end

Example #11: change the banner randomly in an interval loop

Given that you have a method which selects any element from the current jQuery set randomly,
e.g.
$.fn.random = function(){ return this.eq(
  Math.floor(Math.random()*this.length)) }
,
then you can use that to build a banner rotator very easily.

In this example there are four different banners. Every 5 seconds another one fades in, randomly chosen.

As we don't want to wait for the animations finishing we use the original version of .fadeIn() and .fadeOut() here.

$('#banners > *').hide().repeat(5000,true)
   .fadeOut(1000).siblings().random().fadeIn(1000)
.until($);

Some banner text?
some more text here

Some other cool stuff?
this is other text

Even different text
this is new text

Attention!
cheaper, cheaper, cheaper…