title: JavaScript Function which counts number of DOM elements
body: <p>I need to write a function which counts types of elements in the DOM</p>
  
  <pre><code>function setNumbers(){
      var a = 0;
      var b = 0;
      var c = 0;
      var d = 0;
      var span = document.createElement('span');
      span.style.background = 'black';
      var anchors = document.getElementById('anchors');
      var buttons = document.getElementById('buttons');
      var text = document.getElementById('text');
      var events = document.getElementById('events');
  
  
      var elements = document.getElementsByTagName("*");
      for(var i =0; i&lt;elements.length; i++){      
  
          if (elements[i].nodeName === 'A') {
              a++;
              span.innerHTML = "anchors - " + a;      
              span.style.border = '1px solid yellow';
              span.style.color = 'yellow';
              anchors.appendChild(span);
          }
          if (elements[i].nodeName === 'TEXTAREA' || elements[i].nodeName === 'INPUT' ) {
              b++;
              span.innerHTML = "textfields - " + b;           
              span.style.border = '1px solid orange';
              span.style.color = 'orange';
              text.appendChild(span);
  
          }
          if (elements[i].nodeName === 'BUTTON') {
              c++;
              span.innerHTML = "buttons - " + c;          
              span.style.border = '1px solid green';
              span.style.color = 'green';
              buttons.appendChild(span);
  
          }
          if (elements[i].onclick) {
              d++;
              span.innerHTML = "events - " + d;           
              span.style.border = '1px solid pink';
              span.style.color = 'pink';
              events.appendChild(span);
  
          }
      }
  }
  setNumbers();
  </code></pre>
  
  <p>Here is the code. The function has to append the number of elements in relevant div, but appends only textarea elements. Can you please check my function and tell where I missed something? Thanks 
  Here is the <a href="http://jsfiddle.net/acguvd4f/7/" rel="nofollow">fiddle</a></p>