title: Javascript - Cannot read property 'innerHTML' of undefined
body: <p>Why am I getting: <strong>Uncaught TypeError: Cannot read property 'innerHTML' of undefined</strong>?
  I want to get the day, month and year from a "task" so then I can calculate how many days are left to hand in the task, but I get that error.</p>
  
  <pre><code>&lt;div class="task" id="task"&gt;
                  &lt;ul&gt;
                      &lt;li class="title" id="@ta.Id"&gt;&lt;div class="complete"&gt;&lt;/div&gt;@ta.Title&lt;/li&gt;
                      &lt;li class="body"&gt;&lt;b&gt;Project: &lt;/b&gt;@ta.Description&lt;/li&gt;
                      &lt;li&gt;Hand In: @ta.Dia/@ta.Mes/@ta.Año&lt;/li&gt;
                      &lt;li class="leftion"&gt;Days left: &lt;/li&gt;
                      &lt;li class="day" style="display: none"&gt;@ta.Day&lt;/li&gt;
                      &lt;li class="month" style="display: none"&gt;@ta.Month&lt;/li&gt;
                      &lt;li class="year" style="display: none"&gt;@ta.Year&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  var today = new Date();
       var dd = today.getDate();
       var mm = today.getMonth() + 1; //January is 0!
  
       var yyyy = today.getFullYear();
       if (dd &lt; 10) {
           dd = '0' + dd
       }
       if (mm &lt; 10) {
           mm = '0' + mm
       }
       var firstDate = new Date(yyyy, mm, dd);
       var gio = document.getElementsByClassName("task");
       var lele = document.getElementsByClassName("leftion");
       for (var i = 0; i &lt;= gio.length; i++) {
           var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
           var day= document.getElementsByClassName("day")[i].innerHTML;
  </code></pre>
  
  <p><strong>Uncaught TypeError: Cannot read property 'innerHTML' of undefined</strong></p>
  
  <pre><code>        var month = document.getElementsByClassName("month")[i].innerHTML;
          var year= document.getElementsByClassName("year")[i].innerHTML;
           var secondDate = new Date(year, month, day);
  
  
           var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime()) / (oneDay)));
           lele[i].innerHTML = diffDays;
       }
  &lt;/script&gt;
  </code></pre>