Friday, October 31, 2008

[jQuery] Re: How to display random content from external .html file?

On Oct 30, 2008, at 10:38 PM, ricardobeat wrote:

> This should work:
> (...)
>
> $('#quotesContainer').load('quotes.htm',function(){
> var $quotes = $(this).find('p.text');
> var n = $quotes.length;
> var random = Math.floor( Math.random()*n );
> $quotes.hide().eq(random).fadeIn();
> });

Works like a charm! Exactly what I needed. Thanks a lot!

While we're at it... what should I change/add to make it display one
quote for, say, 30 secs then display another one, without needing to
reload a page?

--
Justine

No comments: