[Solved] Text change when background colour changes using Javascript


Simply have the text in an array, ( get it from some elements using jquery – however you want it) iterate through it and change the content inside the div using html() function when you are changing the color.

Simple modification of your code would be something like

function changeColorAndText(element, curNumber){
 curNumber++;
 if(curNumber > 4){
    curNumber = 1;
 }
 element.addClass('color' + curNumber, 500);
 element.html(arr[curNumber]);
 element.attr('class', 'color' + curNumber);
 setTimeout(function(){changeColorAndText(element, curNumber)}, 1000);  
}
var arr = ['hi','hello ','how ','are ','you '];
changeColorAndText($('#testElement '), 0);

JSFiddle

1

solved Text change when background colour changes using Javascript