Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Find word and change every few seconds

How can I change a word every 2-3 seconds using jQuery?

For example:

I have this:

<div>
    <span>This is so</span>
    <span>awesome</span>
</div>

... and I want the awesome to change into cool,fantastic,incredible and keep cycling with loop using fadeOut/fadeIn effect maybe?

Is it possible?

Thanks alot

like image 344
jQuerybeast Avatar asked Sep 15 '11 02:09

jQuerybeast


1 Answers

(function(){

    // List your words here:
    var words = [
        'awesome',
        'incredible',
        'cool',
        'fantastic'
        ], i = 0;

    setInterval(function(){
        $('#changerificwordspanid').fadeOut(function(){
            $(this).html(words[i=(i+1)%words.length]).fadeIn();
        });
       // 2 seconds
    }, 2000);

})();

Give your span an id, and change changerificwordspanid to the id of the span.

JSFiddle Example here

like image 148
Paul Avatar answered Oct 17 '22 16:10

Paul