I want to take the innerHTML of a div and then split the string into words and change the same innerHTML to display each word one by one with a delay in between. My code below at the moment does not work:
document.addEventListener("click", function() {
var text = document.getElementById("article-text");
var textSplit = text.innerHTML.split(" ");
function timeoutFunction()
{
for (var i = 0; i < textSplit.length; i++) setTimeout(function () {
text.innerHTML = textSplit[i];
}, 500);
}
timeoutFunction();
});