Javascript content rotator?

Posted by different on Stack Overflow See other posts from Stack Overflow or by different
Published on 2010-03-17T14:33:34Z Indexed on 2010/03/17 14:41 UTC
Read the original article Hit count: 215

Filed under:

I’ve got the basics of a content rotator done, the only problem is it doesn’t loop itself back to the beginning and I cannot figure out why! It is a very simple javascript script:

window.onload = function() { setInterval("transition()", 5000); }

    function transition()
    {
        var y = document.getElementById("featured").getElementsByTagName("li");
        for (var i=0;i<y.length;i++)
        {
            if (y[i].className == "current")
            {
                y[(i+1)].className = "current";
                y[i].className = "";
                break;
            }
        }
    }

It keeps stopping at the end of the list, basically I just want it to loop. Any help?

© Stack Overflow or respective owner

Related posts about JavaScript