$(document).ready(function(){ //$("#theText").html(function(i, oldHTML) { //console.log (oldHTML.replace(/ /g, '')); //return oldHTML.replace(/ /g, ''); //}); $("#theText").html('' + $("#theText span").html().replace(/ /g, '') + ''); var delay1 = 200; var delay2 = 400; var $words = $('.word'); $words.removeClass('effacer'); $words.removeClass('separated'); $words.each(function (i){ var myElement = $words[i]; setTimeout(function(){ $(myElement).addClass('effacer'); }, i*delay2 + 4000); setTimeout(function(){ }, i*delay2 + 3000); setTimeout(function(){ $(myElement).removeClass('separated'); }, i*delay2 + 1000); }); });