title: JQuery to add incremental number to div with preceding 0
body: <p>I have a number of CMS generated items that I could like to count and display the item's number in a <code>div</code></p>
  
  <p>I'm using this so far:</p>
  
  <pre><code>$('.course-number').each((i, e) =&gt; $(e).text(i+1));
  </code></pre>
  
  <p>This correctly outputs 1, 2, 3, 4 etc into the <code>div.course-number</code> as expected.</p>
  
  <p>But for aesthetic reasons I would like <strong>numbers below 10 to have a preceding zero</strong> – so the output was 01, 02, 03, 04 etc then 10, 11, 12 etc without a preceding zero.</p>
  
  <p>Can anybody help me achieve this?</p>
  
  <p>(<strong>update:</strong> the proposed <a href="https://stackoverflow.com/questions/1267283/how-can-i-pad-a-value-with-leading-zeros">duplicate</a> does not provide a complete answer that addresses each need: (1) count each element (2) output the number as text inside the element (3) add a preceding zero IF less than 10)</p>