title: getElementsByTagName not working in chrome and safari
body: <p>I'm using the javascript method getElementsByTagName("a") to call all 'a' tags and do some effect with them. The method works in FF and Opera but not in Chrome and Safari.
  When I look in the debugging tools of Chrome and Safari they say: <strong><em>"Uncaught TypeError: Cannot call method 'getElementsByTagName' of null"</em></strong></p>
  
  <p>Why is that and what's the fix? Please can someone advise me on this?</p>
  
  <p>Many Thanks in advance.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>function popUpSAPWindow(){
  // Find all links in the page and put them into an array.
  var linksInOrderLinesTable = document.getElementById("orderLinesTable").getElementsByTagName("a"); // The line doing the error
  var linksLen = linksInOrderLinesTable.length;
  
  // If the link text is 'SAP' then modify the attributes
  for(var i = 0; i &lt; linksLen; i++){
      if(linksInOrderLinesTable[i].innerHTML == "SAP"){
          // Store the 'href' value of each SAP link.
          var sapHref = linksInOrderLinesTable[i].href;
  
          // Modify the attributes of each SAP link.      
          linksInOrderLinesTable[i].setAttribute("href", "javascript:return false;");
          linksInOrderLinesTable[i].setAttribute("onclick", "sapNewWindow(\'" + sapHref + "\')");
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>It works with this HTML:</p>
  
  <pre><code>&lt;table id="orderLinesTable" summary="List of orders made by customers that the administrator can pick and deal with"&gt;
  &lt;tr&gt;
      &lt;th&gt;Status&lt;/th&gt;
      &lt;th&gt;Basket id&lt;/th&gt;
      &lt;th&gt;Order line id&lt;/th&gt;
      &lt;th&gt;Product&lt;/th&gt;
      &lt;th&gt;Company&lt;/th&gt;
      &lt;th&gt;Catalogue&lt;/th&gt;
      &lt;th&gt;Date&lt;/th&gt;
      &lt;th&gt;Details&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;Accepted&lt;/td&gt;
      &lt;td&gt;236569&lt;/td&gt;
      &lt;td&gt;207&lt;/td&gt;
      &lt;td&gt;OS Master Map&lt;/td&gt;
      &lt;td&gt;NHS&lt;/td&gt;
      &lt;td&gt;Standard&lt;/td&gt;
      &lt;td&gt;1 Aug 10&lt;/td&gt;
      &lt;td&gt;&lt;a href="/orderLineDetails.html"&gt;Normal&lt;/a&gt; &lt;a href="/orderLineDetails.html"&gt;SAP&lt;/a&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;New&lt;/td&gt;
      &lt;td&gt;236987&lt;/td&gt;
      &lt;td&gt;528&lt;/td&gt;
      &lt;td&gt;Code-Point&lt;/td&gt;
      &lt;td&gt;BT&lt;/td&gt;
      &lt;td&gt;Standard&lt;/td&gt;
      &lt;td&gt;9 Aug 10&lt;/td&gt;
      &lt;td&gt;&lt;a href="/orderLineDetails.html"&gt;Normal&lt;/a&gt; &lt;a href="/orderLineDetails.html"&gt;SAP&lt;/a&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p></p>
  
  <p>But when I'm on other pages it gives the error mentioned.</p>