Trying to debug the following code
function split(toRead, toReplace, speed) {
var words = $(toRead).html().split(" ");
for (var i = 0; i < words.length; i++) {
//console.log(words[i]);
setTimeout(function () {
$(toReplace).html(words[i]);
}, speed * i);
}
}
The code should receive a block of text 'toRead', break it down to words, and then replace 'toReplace' with each word, with a set time interval. Like http://www.spreeder.com/ does.
However, it doesn't seem to work. I'm guessing this has something to do with the timing and the for loop (Seems like the for loop ends regardless of the timer, making words[i] read the same word every time).
Really appreciate any help, thanks guys & gals :) Cheers, Nir