title: Can jQuery .each be used when setting an interval within that sets an element's .html()?
body: <p>I have a page with multiple <code>.countdown-element</code> divs which I want to contain a countdown.</p>
  <p>I am iterating through each <code>.countdown-element</code> and attempting to apply a countdown timer to each of them.</p>
  <p>The  <code>$(this).html()</code> parts in the <code>setInterval</code> do not trigger. I assume this is related to using <code>.each</code> and it's going through the other <code>.countdown-element</code> divs before it can run.</p>
  <p>How can I get the countdown to be applied to each of the <code>.countdown-element</code> divs?</p>
  <pre><code>$( '.countdown-element' ).each( function() {
  
      // Set the date we're counting down to
      var countDownDate = new Date( $(this).attr('data-countdown-to') ).getTime();
      console.log( 'test: ' + countDownDate );
  
      // Update the count down every 1 second
      var x = setInterval(function() {
  
        // Get today's date and time
        var now = new Date().getTime();
  
        // Find the distance between now and the count down date
        var distance = countDownDate - now;
  
        // Time calculations for days, hours, minutes and seconds
        var days = Math.floor(distance / (1000 * 60 * 60 * 24));
        var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  
        // Display the result in the element with id=&quot;demo&quot;
        $(this).html( days + &quot;d &quot; + hours + &quot;h &quot; + minutes + &quot;m &quot; + seconds + &quot;s &quot; );
  
        // If the count down is finished, write some text
        if (distance &lt; 0) {
          clearInterval(x);
          $(this).html( 'EXPIRED' );
        }
      }, 1000);
  
  });
  </code></pre>
  <p>Div markup is (note the data attribute here is dynamic from PHP hence why I need to apply it as an attribute and use that from the JS):</p>
  <pre><code>&lt;div class=&quot;countdown-element&quot; data-countdown-to=&quot;2021-02-10 12:00&quot;&gt;&lt;/div&gt;'
  </code></pre>