title: Why is javascript looping through elements but executing jQuery function on all of them simultaneously?
body: <p>I have a text "HELLO" and I want to loop through every letter and animate it so it fades in and out.Here's my code.</p>
  
  <p>EDIT: I put the answer in the snippet to see it in action.</p>
  
  <p>Code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
    var $letters = $('p[id^="letter-"');
    $letters.each(function(index) {
      $(this).css({
        'animation': 'pulse 500ms ' + index * 500 + 'ms' + ' linear'
      })
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>html,
  body {
    font-size: 45px;
  }
  
  p {
    position: absolute;
    left: 400px;
    top: 100px;
    color: rgba(0, 0, 0, 0);
  }
  
  @keyframes pulse {
    0% {
      color: rgba(0, 0, 0, 0);
    }
    25% {
      color: rgba(0, 0, 0, 0.5);
    }
    50% {
      color: rgba(0, 0, 0, 1);
    }
    75% {
      color: rgba(0, 0, 0, 0.5);
    }
    100% {
      color: rgba(0, 0, 0, 0);
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;p id='letter-0'&gt;H&lt;/p&gt;
  &lt;p id='letter-1'&gt;E&lt;/p&gt;
  &lt;p id='letter-2'&gt;L&lt;/p&gt;
  &lt;p id='letter-3'&gt;L&lt;/p&gt;
  &lt;p id='letter-4'&gt;O&lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>And here's a link to a <a href="https://codepen.io/anon/pen/bRMRJP" rel="nofollow noreferrer">pen</a>.
  Instead of doing the animation one letter at a time, it's animating the whole thing at once.How can this be fixed? Shouldn't a loop finish executing all the commands and <em>then</em> move on to the next step? Maybe there's a better approach to this that I don't know of? </p>