I am using jquery to set up a typewriter effect on a div. I am not using css to do this because the sentence will be cover more than 1 line. The problem I am facing is getting the cursor to blink, then fade away when line is typed.

Html:

```
<div class="typewriter">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>

```

JS

```
/*****Start Typewriter effect*****/
  $('.typewriter').css('display', 'none');
  setTimeout(function(){
    $('.typewriter').css('display', 'flex');

    var str = $('.typewriter').html() + 1,
    i = 0,
    isTag,
    text,
    cursor = "|",
    timer;

    (function type() {
      text = str.slice(0, ++i);
      if (text === str){ 
        return;
      }
      $('.typewriter').html(text + " " + cursor);
      timer = setTimeout(type, 40);
    }());
  }, 300);
  /*****End Typewriter effect*****/

```

Here is a jsfiddle
<https://jsfiddle.net/ht4569wv/>