Skip to content

Instantly share code, notes, and snippets.

@akinjide
Created November 19, 2018 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akinjide/f6f8781eb566b1749c5ee724dec5344d to your computer and use it in GitHub Desktop.
Save akinjide/f6f8781eb566b1749c5ee724dec5344d to your computer and use it in GitHub Desktop.
var colors = ["black", "blue", "brown", "green"];
var doc = document.getElementById("content");
var text = doc.innerHTML.split(" ");
function changeColor() {
doc.innerHTML = "";
text.forEach(function(word, i) {
if (i != text.length) {
word += "\n";
}
var colourIndex = (i + 1) % colors.length;
var node = document.createElement("span");
node.textContent = word;
node.style.color = colors[colourIndex];
doc.appendChild(node);
});
}
// setInterval(changeColor, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment