document.getElementById() works in IE but not Firefox [SOLUTION]

document.getElementById() is one of the most useful javascript functions you can use.

However when developing for different browsers remember that Internet Explorer also allows you to reference object names in addition to object ids. So if you are wondering why something is working in IE but not FF, check to make sure that you are referencing the object by its ID and not its name.

example: You have an image with name='myImageName' and id='myImageID'

IE will allow you to call document.getElementbyId('myImageName') and it will work, if you try this with FF or any other browser, it will not work.

For it to work on all browsers it would be document.getElementById('myImageID'), since you are actually referencing the ID and not the name of the object, this will work on all browsers. This is also semantically correct.

It may sound trivial, but in terms of troubleshooting, this has been known to pop up.

Just a troubleshooting tip for cross browser development.


Keywords: document.getElementById() not working in FF, Safari, netscape, mozilla


Submit a Comment