Typwriter effect on text using java

i am trying to add typewriter animation to my html text as soon as the url loads, using the code below. Please check why this might not be working.

  <!DOCTYPE html>
    <html>
    <body>
    
    
    <p onload="typeWriter()" id="demo"></p>
    <style>
    p   {
      color: Black;
      font-family: arial;
      }
    </style>
    <script>
    var i = 0;
    var txt = 'Lorem ipsum dummy text blabla.';
    var speed = 50;
    
    function typeWriter() {
      if (i < txt.length) {
        document.getElementById("demo").innerHTML += txt.charAt(i);
        i++;
        setTimeout(typeWriter, speed);
      }
    }
    
    </script>
    
    </body>
    </html>

1 thought on “Typwriter effect on text using java”

Leave a Comment