Tuesday, March 24, 2009

getElementById compared in IE6, IE7 and IE8

Hi guys!

These days I was enjoying the new Internet Explorer 8 and were observing the differences with the previous versions of the browser.

I encountered a problem connected with the getElementById method. It was working OK in IE6 and IE7, and now in IE8 it suddenly stopped working.

How does getElementById works in IE6/IE7
In IE6 and IE7, the method getElementById would get an element provided either the ID or the Name attribute of the element. What is more, it matches it case-insensitevily.

In Comparison
In IE8 it does exactly what it says and what it should do - it gets the element only by the ID attribute and it matches case-sensitively.

The reason why the old code wasn't working in IE8 was because someone has used the getElementById to get an element on the page provided it's Name. Which apparently won't work in IE8.

More on this
More on this, Here (Check the Remarks paragraph)


Max Graham said...


getElementById was horribly broken in IE6 and IE7. Thankfully in IE8 (in standards mode) they fixed this method so it actually searches correctly, and returns the correct results.

You can see the bug and a great workaround to fix it in IE6 or IE7 here


this bug is also related



cypressx said...

Thanks, I really appreciate your information and help !


Павелъ Дончевъ said...

This is one more step toward getting IE healthy again. To me it seems Microsoft left it for a few years without adult supervision ;). As they knew it is dominating the market.

Hopefully one day we will develop one function for all browser and not 2-3 versions of the same function for each browser. It is very annoying ...

Nice post, I didn't know much about getElementById!

cypressx said...

Thanks for your valuable feedback !

P.S. Unfortunately, I can't say I am very impressed with the new version of the IE8 :(

Anonymous said...

It's always something with IE! Go get firefox. If you must develop for IE then use a javascript libray such as jquery to help abstract some of the problems of developing for IE

Unknown said...

I was very pleased to find this web-site.I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.