Most often the reason is simple "your markup is wrong!".
Yes, the document.getElementById() returns the first element with the given id.
However in IE, the document.getElementById() also returns the first element who's ID or name matches the provided ID. Consider the following markup.
<input type="text" name="txtTitle" />
Here only the name attribute is specified, the ID is not.
Now when you will use document.getElementById( "txtTitle"), it would return the text input in
IE, but it would return null in firefox because the id attribute is not specified in the markup. Also
in IE, the match performed is case-insensitive whereas in FF it is case-sensitive.
So, always remember to treat the document.getElementById() as if it would only return
the element with the given id, regardless of what IE returns.
Points to remember:
- The document.getElementById() in IE also searches the element with the given name
- In firefox, the document.getElementById() only returns the element
who's id attribute matches with the given value. - The search is case-sensitive in firefox whereas in IE, it is not.
In conclusion, firefox is more stricter as it should be, whereas IE is more relax, trying to be smarter, possibly opening doors to nonstandard coding.
Happy debugging!