Today is a good day to code

IE 7 Confused by HTML Name and Id Attributes

Posted: December 31st, 1969 | Author: | Filed under: Uncategorized | No Comments »

IE 7 Confused by HTML Name and Id Attributes

Picture of IrvinNow this is exactly what I am talking about with IE. How could anyone release a product with a known bug like this? If there are two elements in the DOM at any single time, with one having an id=”someId” and name=”someId”, and you use:

obj.getElementById(“someId”);

IE will return the last occurring element with either an id=”someId”, or a name=”someId.” Such that markup like:

ipsum lorem factum


lorem factum ipsum

When accessed like:

var obj = document.getElementsByName(“myDiv”);
// if you use firebug
console.log(obj.length);

Would equal 2 instead of 1. This is a horrible error, and it is inexcusable that Microsoft didn't fix this bug in IE 6, let alone IE 7. IE is garbage, and more importantly it wastes developer's time with ignorant bugs like that one.

A co-worker found information on PPK document.getElementById() returns element with name equal to id specified