var i = 0, nodes = document.getElementById('any').getElementsByTagName('li'), d = nodes.length - 1; setInterval(function () { nodes[i].className = 'myClass', nodes[i == d ? d : i].className = '', i = i == d ? 0 : i + 1; }, 1000);