I have a number of CMS generated items that I could like to count and display the item's number in a div
I'm using this so far:
$('.course-number').each((i, e) => $(e).text(i+1));
This correctly outputs 1, 2, 3, 4 etc into the div.course-number
as expected.
But for aesthetic reasons I would like numbers below 10 to have a preceding zero – so the output was 01, 02, 03, 04 etc then 10, 11, 12 etc without a preceding zero.
Can anybody help me achieve this?
(update: the proposed duplicate 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)