title: How to call a script function with same div name in php?
body: <pre><code>&lt;p&gt;Success login. You will be redirected in &lt;span class="counter"&gt;10&lt;/span&gt; second(s).&lt;/p&gt;
  &lt;p&gt;Wrong username/password. You will be redirected in &lt;span class="counter"&gt;10&lt;/span&gt; second(s).&lt;/p&gt;
  
  &lt;script type="text/javascript"&gt;
  function countdown() {
      var i = document.getElementByClassName('counter');
      if (parseInt(i.innerHTML)&lt;=0) {
          location.href = 'login.php';
      }
      i.innerHTML = parseInt(i.innerHTML)-1;
  }
  setInterval(function(){ countdown(); },1000);
  &lt;/script&gt;
  </code></pre>
  
  <p>Before it was <code>id=counter</code>, and it works for one span tag. But I want two tags to share the same function. I tried changing it to <code>getElementByClassName</code> but it doesn't work. Can anyone tell me why?</p>