+ 2

Why my text is not changing every 6 sec

Text animation with javascript https://code.sololearn.com/W5MrnB3lRKBz/?ref=app

8th Dec 2021, 9:45 PM
D Doyen
D Doyen - avatar
4 Respuestas
+ 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 👍
9th Dec 2021, 1:16 AM
Ipang
+ 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); }
8th Dec 2021, 10:14 PM
SoloProg
SoloProg - avatar
+ 1
Tks
9th Dec 2021, 5:06 PM
D Doyen
D Doyen - avatar
0
And Why
9th Dec 2021, 5:06 PM
D Doyen
D Doyen - avatar