l'essentiel est invisible pour les yeux

Friday, December 14, 2007

[WTF!] IE7のdocument.getElementByIDの挙動


<input type="text" value="Shun" name="first_name"/>
<input type="text" value="Mori" name="last_name"/>
<input id="first_name" value="rakuto"/>

<script type="text/javascript"> //<![CDATA[
document.getElementById('first_name').value; // => 'Shun' on IE7, 'rakuto' on Firefox 2.x and Safari 3.x
document.getElementById('last_name').value; // => 'Mori' on IE7, undefined on Firefox 2.x and Safari 3.x
// ]]></script>



The 'document.getElementById' means 'document.getElementByIdOrName' on IE 7.