jquery - Text change when background colour changes using Javascript -
below javascript changing background colour of website, there way change text in body of page when change in colour occurs?
function changecolor(element, curnumber){ curnumber++; if(curnumber > 4){ curnumber = 1; } console.log(curnumber); element.addclass('color' + curnumber, 500); // previous classes removed. element.attr('class', 'color' + curnumber); settimeout(function(){changecolor(element, curnumber)}, 1000); } changecolor($('#testelement'), 0);
simply have text in array, ( elements using jquery - want it) iterate through , change content inside div using html()
function when changing color.
simple modification of code 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);
Comments
Post a Comment