Re: Selectors API: Multiple elements with the same ID

On Jan 27, 2007, at 7:56 PM, Boris Zbarsky wrote:

>
> Robert Sayre wrote:
>> MSDN says it returns the "first object".
>> <http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/ 
>> getelementbyid.asp>
>
> For what it's worth, that's not what Gecko does, and I personally  
> would rather not try to enforce that -- it's somewhat expensive to  
> do so in the face of DOM mutations.

I tried to make some test cases to figure out the difference (in  
current WebKit sources we changed to return the first match in  
document order to match IE, and, we thought, Firefox), but Gecko's  
getElementById seems to be really buggy. For instance, this alerts null:

<div id="foo">
</div>
<script>
alert(document.getElementById("foo"));
</script>

This is with Firefox 2.0.0.1 on Mac OS X. What am I doing wrong here?

Regards,
Maciej

Received on Sunday, 28 January 2007 22:59:29 UTC