Fake Typer

Simple function that reveals some text one character at a time to make it look like it is being typed out.

by Trevin Avery

HTML

<div class='output'></div>

JavaScript

document.addEventListener('DOMContentLoaded', function() {
  let output = document.querySelector('.output')
  
  function sendMsg(out, msg) {
  	let sent = ''
    let send = function() {
    	sent += msg.charAt(sent.length)
      output.innerText = sent
      if (sent.length != msg.length) {
      	setTimeout(send, 50)
      }
    }
    send()
  }
  
  sendMsg(output, 'this is a test of really long text stuff')
})