I have some text on my website written in HTML:
<h2 class="sub">Here is <span id="my_words">word1</span>.</h2>
I currently have JavaScript written that makes the word change dynamically on the site:
$(function () {
count = 0;
wordsArray = ["word1", "word2", "word3"];
setInterval(function () {
count++;
$("#my_words").fadeOut(1000, function () {
$(this).text(wordsArray[count % wordsArray.length]).fadeIn(1000);
});
}, 2000);
});
How can I make it so that the color of the word changes each time it cycles? Either from pre-defined colors or randomly.