+ 2
Why my text is not changing every 6 sec
Text animation with javascript https://code.sololearn.com/W5MrnB3lRKBz/?ref=app
4 Réponses
+ 2
Move the script block after the body block. It's not running because <txt> is not correctly referencing the <h1>, it was not rendered on the document yet when your script runs 👍
+ 1
let txt= document.getElementById("message");    
let text = [], y=0; 
text[0] = "MSG1"; 
text[1] = "MSG2"; 
text[2] = "MSG3"; 
setTimeout("changeText()", 6*1000); 
function changeText() {     
    txt.innerText = text[y]; 
    y++;
    if(y>=text.length) y=0;  
    setTimeout("changeText()", 6*1000); 
}
+ 1
Tks
0
And Why



