title: Cross-browser getClassName JavaScript function
body: <p>I'm working on a small project that needs to get all elements by className, there is obviously the HTML5 .getElementsByClassName, but I'm trying to create a little function that provides a small polyfill for it, it's just not working. any help much appreciated. Or if there is an easier way of doing this.</p>
  
  <pre><code>function getClassName(element) {
  if(!document.getElementsByClassName(element)) {
      var retnode = [];
      var myclass = new RegExp('\\b'+element+'\\b');
      var elem = this.getElementsByTagName('*');
      for (var i = 0; i &lt; elem.length; i++) {
          var classes = elem[i].className;
          if (myclass.test(classes)) retnode.push(elem[i]);
      }
      return retnode;
  } else {
      document.getElementsByClassName(element);
  }
  } 
  </code></pre>
  
  <p>Then calling it like so:</p>
  
  <pre><code>document.getClassName('active'){
  active.className += 'new';
  }
  </code></pre>