Cycling through <li>s with setInterval
A test of the Javascript setInterval method being used to cycle through the text of <li> tags.
by Snowsickle
HTML
<ul id="news">
<li>
How Instagram Is Winning Gold at the 2012 Olympics [INFOGRAPHIC]
</li><li>
Flickr Photo of Insect Identified As Never-Before-Seen Species [VIDEO]
</li><li>
The Upside to the End of the Olympics [COMIC]
</li><li>
40 Digital Media Resources You May Have Missed
</li><li>
19 Resources to Improve Your Photo and Video Skills
</li><li>
Top 10 Twitter Pics of the Week
</li><li>
Can Employees Be Trusted to Work From Home? [INFOGRAPHIC]
</li><li>
Capture Ghosts at Foursquare Spots With ‘Ghostbusters’ iOS Game
</li><li>
Dog Is Terrified of Low-Fat Lamb Jerky [VIDEO]
</li><li>
5 Tips to Take Food Photos Good Enough to Eat
</li><li>
The 10 Most Stunning Images of Mars in History
</li><li>
The Many Looks of Spiderman Over the Past 50 Years [INFOGRAPHIC]
</li><li>
Top Ten GIFs of the Week
</li><li>
Romney and Obama Both Called Their Veeps the ‘Next President’ [VIDEO]
</li><li>
Paul Ryan Visited Facebook, Met Zuckerberg [PICS]
</li><li>
Romney’s Logo Looks Like Toothpaste [PICS]
</li><li>
Paul Ryan, Romney’s VP Pick, Has Sizable Online Presence
</li><li>
Get Back in Kitchen With This Specialized Recipe Site
</li>
</ul>
<p id="test"></p>
CSS
ul {
display: none;
}
JavaScript
var news = document.getElementById('news').getElementsByTagName('li');
var newsItem = 0;
var speechInterval = setInterval(function(){
//speechapi.speak(news[newsItem].innerHTML, "male");
document.getElementById('test').innerHTML = news[newsItem].innerHTML;
if (++newsItem === news.length){
window.clearInterval(speechInterval);
}
}, 2000);