Because HTML doesn't render line feeds, you need to add a condition in your function or adapt your HTML code.
Solution #1
Update your Javascript function, add a special case in your first if
statement:
var i = 0;
var text = "Animation - Web Development- Video Editing Become a member & More.";
function typeWriter(){
if(i < text.length){
if(text.charAt(i) === "\n")
document.getElementById("text").innerHTML += "<br/>";
document.getElementById("text").innerHTML += text.charAt(i);
i++;
setTimeout(typeWriter, 50);
}
}
typeWriter();
In that case, HTML will render <br/>
tag by adding a new line. Don't forget to add the \n
in your text
variable.
Solution #2:
Use <pre>
HTML tag, not recommended but content will be rendered too, without changing your Javascript function.
<pre id="text"></pre>