title: Javascript - Change ID to Class to be able to use the class multiple times in a page
body: <p>I'm trying to display parts of the date on a page using the ID, I have to use the ID multiple times on a page, and I've been told that I need to change that to class, and I'm unsure how to do that.</p>
  
  <p>I've created this <a href="https://jsfiddle.net/3m8cgan9/1/" rel="nofollow noreferrer">jsfiddle</a>.</p>
  
  <p>The HTML is as follows, but I need to use some of those ID's multiple time, and using a second instance of it doesn't show/work.</p>
  
  <pre><code>&lt;p&gt;The date is &lt;a id="date"&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;The current month and year is &lt;a id="month-year"&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;The current day and month is &lt;a id="day-month"&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;The current year is &lt;a id="year"&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;The current month is &lt;a id="month"&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;Today is the &lt;a id="day"&gt;&lt;/a&gt; of &lt;a id="month"&gt;&lt;/a&gt;&lt;/p&gt; 
  </code></pre>
  
  <p>In the last example <code>&lt;a id="month"&gt;</code> will not show.</p>
  
  <p>the JS I'm using is as follows.</p>
  
  <pre><code>var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  var n = new Date();
  var y = n.getFullYear();
  var m = n.getMonth();
  var d = n.getDate();
  var dateObject = document.getElementById("date");
  if (dateObject) dateObject.innerHTML = d + " " + months[m] + " " + y;
  var month_year = document.getElementById("month-year"); 
  if (month_year) month_year.innerHTML = months[m] + " " + y;
  var day_month = document.getElementById("day-month");
  if (day_month) day_month.innerHTML = d + " " + months[m];
  var year = document.getElementById("year");
  if (year) year.innerHTML = y;
  var month = document.getElementById("month");
  if (month) month.innerHTML = months[m];
  var day = document.getElementById("day");
  if (day) day.innerHTML = d;
  </code></pre>
  
  <p>How can I change the above code so I can use the ID/class multiple times on a page?</p>