title: JavaScript - Get text in div by class
body: <p>I am trying to get just the content/text of div by class name using javascript. The outcome isn't what i have expected. I did try to push it into array but it does not seems to be working. Please help!</p>
  
  <p>What i have done so far :</p>
  
  <p>JavaScript: </p>
  
  <pre><code>var elements = document.body.getElementsByClassName("headline-bar");
  
  window.onload = function() {
  
      var year= document.getElementById("year");
      for (i=0;i&lt;elements.length;i++)
      {
          var Entry = document.createElement("option");
          Entry.text = elements[i];
          year.add(Entry ,null);
      }
  }
  </code></pre>
  
  <p>Html:</p>
  
  <pre><code>&lt;form&gt;
  &lt;select id="year"&gt;
  &lt;/select&gt;
  &lt;/form&gt;
  &lt;input type="submit" value="Submit"&gt;
  
   &lt;div class="headline-bar"&gt;2015&lt;/div&gt;  
   &lt;div class="headline-bar"&gt;2014&lt;/div&gt;   
  </code></pre>
  
  <p>Output:</p>
  
  <p><a href="https://i.stack.imgur.com/lWUwT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lWUwT.png" alt="enter image description here"></a></p>
  
  <p>Desire outcome:</p>
  
  <p><a href="https://i.stack.imgur.com/LpGJ4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LpGJ4.png" alt="enter image description here"></a></p>