var myTexts = new Array("My text 1",
"My text text",
"My text my text",
"My text other");
var currentText = 0;
var timeout = setInterval(nextText, 5000);
function nextText() {
if (currentText >= myTexts.length) {
currentText = 0;
} else {
currentText++;
}
$('em').html(myTexts[currentText]);
}
Basically what the code above does is:
- set your text within an array
- set an interval to call nextText() every 5 seconds
- in the function check which text to show (based on the length of your array)
- change the text within your 'em' element with jquery's html()-method.
-edit: typos...