The verdict? getElementById() has inconsistent behavior in IE7 and prior document modes. Instead of searching for an element by ID, Microsoft programmers of old broke with the specification and had Internet Explorer return the first element with the matching ID or Name property.
<div name="MyElement" id="SomethingElse"></div> <div id="result"></div>
<script> var id = "MyElement"; var element = document.getElementById(id); if(element) document.getElementById("result").innerHTML = "Found element with id of " + id + "."; else document.getElementById("result").innerHTML = "Element with id of " + id + " was not found!"; </script>
When running the above code a modern browser or IE8+ document mode, the result will be what you probably expect:
Element with id of MyElement was not found!
However, you’ll be greeted with the following unexpected result when running in IE7 document mode or below:
Found element with id of MyElement.