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.
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;
}
In newer browsers, if(document.getElementById)
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.
The reason I'm asking, is becuase this code reads the name
(not id
) 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.
This reading of the name
from attributes such as a <tr>
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.