title: simple dom class selector
body: <pre><code>&lt;ul&gt;
    &lt;li&gt; &lt;div class="time"&gt; at 2011-02-05 17:44:28&lt;/div&gt;&lt;/li&gt;
    &lt;li&gt; &lt;div class="time"&gt; at 2011-02-05 17:40:20&lt;/div&gt;&lt;/li&gt;
    &lt;li&gt; &lt;div class="time"&gt; at 2011-02-05 17:15:11&lt;/div&gt;&lt;/li&gt;
    &lt;li&gt; &lt;div class="time"&gt; at 2011-02-05 17:04:14&lt;/div&gt;&lt;/li&gt;
    &lt;li&gt; &lt;div class="time"&gt; at 2011-02-05 15:54:56&lt;/div&gt;&lt;/li&gt;
  &lt;/ul&gt;
  
  //Reformat timeStamps
  var timeIndex = 0;
  while (timeIndex &lt; 51)
  {
    var timeIndexHTML = document.getElementsByClassName("time")[timeIndex].innerHTML;
    timeIndexHTML = "Reformatted time";
    document.getElementsByClassName("time")[timeIndex].innerHTML = timeIndexHTML;
    timeIndex++;
  }
  </code></pre>
  
  <p>How can I detect the last element of a class, and then make 51 a variable?</p>
  
  <pre><code>//
  //*****************************EDITS HERE**************************************
  //
  //Example:
    var LAST_ELEMENT_OF_CLASS = someMagicCode("time");
  </code></pre>
  
  <p>and then </p>
  
  <pre><code>while (timeIndex &lt; LAST_ELEMENT_OF_CLASS +1){...}
  </code></pre>
  
  <p>Note it currently doesn't work because it tries to evaluate </p>
  
  <pre><code>document.getElementsByClassName("time")[5]
  </code></pre>
  
  <p>Which doesn't exist</p>