“Sad little piece of software”
What do you think this code will do?
<html> <body> <a name="one">an anchor</a> <hr /> <div id="one">a div</div> <hr /> </body> <script> document.writeln("Element with id 'one' is '" + document.getElementById("one").innerHTML + "'"); </script> </html>
You would think that it will print that element with id one is a div. Yep, and Firefox, Chrome and Safari will agree with you. But not IE🙂. For IE getElementById is synonym with getElementByName. No matter the version – 7, 8 or the mighty IE 9. I don’t know if you would guess, but if you put the div first, it has the expected behavior.
So, getElementById, in IE, returns the first element that has the id or name attribute, equal to the given value. Good to know. But sad.