title: Javascript getting the number of elements in getElementsByClassName
body: <p>I have the following javascript code: </p>
  
  <pre><code>b = document.getElementsByClassName('name1');
  c = document.getElementsByClassName('name2');
  if (b.length != 0) {
      document.getElementByTagName('body')[0].innerHTML = b[0].innerHTML 
  else if (c.length != 0) {
      document.getElementByTagName('body')[0].innerHTML = c[0].innerHTML
  }
  else document.getElementByTagName('body')[0].innerHTML = 'error';
  </code></pre>
  
  <p>But I am not getting the desired rendering. The whole page renders even when divs with class name name1 and name2 are present.</p>
  
  <p>What am I doing wrong?</p>