title: elem is undefined?
body: <p>When I run the following piece of code, the firebug console says that elem is undefined, although...it isn't!</p>
  
  <pre><code>var domTools = {};
  domTools.searchInElements = function (elem, pattern) {
      if (pattern.constructor !== RegExp) {
          throw "Pattern must be a RegExp";
      }
      if (elem.constructor !== String) {
          throw "Element must be a String";
      }
      elem = document.getElementsByTagName[elem];
      var matches = [];
      for (e = 0; e &lt; elem.length; e++) {
          if (pattern.test(elem[e].innerHTML)) {
              matches.push(elem[e]);
          }
      }
      return matches;
  }
  domTools.searchInElements("p", /hello/);
  </code></pre>
  
  <p>It gives me the error during the <code>for</code> statement. All this code is being run whle the page is already loaded. Why is this happening?</p>