Javascript Dom Quirk In IE using getElementById

This is a fun one I found today - using getElementById() in IE7 to find a dom element on the page, if you are getting some interesting errors then one possibility is that you have two elements with the same id - or the same name attribute it seems.

The first thing to check really - have a look through the source code for another dom element of the same id. The generated source code if your page is dynamically creating some dom elements.

However, if you cannot find that then perhaps an element of the same name exists which is confusing IE and apparently some versions of Opera.

input name="unique_id"

can be returned when attempting to retrieve:

input id="unique_id"

So, hopefully you have found this solution and stopped swearing at the screen by now. This error can throw up all manner of interesting error codes depending on your javascript.

Another useful tip I found which made debugging this dom quirk a little easier was this one liner command for emptying the temporary files on IE7:

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

This saved me a lot of mouse clicks!