title: What is the meaning of this legacy code?
body: <p>This is a piece of js code that dates back to Netscape Navigator days. I can't figure out or find the reason why this person did it this way. </p>
  
  <pre><code>function id(i)
  {   
  
     var e;
     if (document.getElementById)
       return document.getElementById(i);
     else if (document.all)
       return document.all[i];
     else if (document.layers)
       return document.layers[i];  
  
     return null;
  }
  </code></pre>
  
  <p>In newer browsers, <code>if(document.getElementById)</code> is always going to be true. It looks like it's checking to see if that function is there, but I'm not really sure.</p>
  
  <p>The reason I'm asking, is becuase this code reads the <code>name</code> (<strong>not</strong> <code>id</code>) of elements that shouldn't have the name attribute from browsers IE8 and below. I'm tasked with trying to get it working more effectively on newer browsers. But first, I really need to understand the meaning of this code. </p>
  
  <p>This reading of the <code>name</code> from attributes such as a <code>&lt;tr&gt;</code> is done else where and it was a pretty simple fix of using it as a custom attribute. This piece I included touches many more pieces and isn't as straightforward.</p>