0
{Solved}Why not working?
4 Respostas
+ 8
You tried to read the value from heading "type" into "txt" variable when DOM is not yet completely loaded, also the heading value is undefined, better get the heading text by its innerHTML instead.
Also there was no code to update "txt" variable when we change heading "type" text. That way "txt" variable will only contain the initial text of heading "type". I have modified the JS code a bit, try and see if this works for you : ).
var i;
var txt;
var speed = 150;
function updateText() {
txt = document.getElementById("type").innerHTML;
i = 0;
document.getElementById("demo").innerHTML = "";
}
window.onload = function() {
updateText();
var demo = document.getElementById("type");
demo.addEventListener("input", updateText);
}
function triter() {
if (i < txt.length) {
document.getElementById("demo").innerHTML += txt.charAt(i);
i++;
setTimeout(triter, speed);
}
}
Hth, cmiiw
+ 5
You're welcome : )
+ 3
thanks
+ 1
what your program must to do?