Yes, getElementById returns the first one found, i.e. the first one in the
dom, if there are multiple nodes with the same id.

On 6/12/07, Aaron Heimlich <[EMAIL PROTECTED]> wrote:

On 6/12/07, Dan G. Switzer, II <[EMAIL PROTECTED]> wrote:
>
> Plus, what happens if you have:
>
> <div id="bam" />
>
> <span id="bam" />
>
> What if you need to retrieve the span tag? If it's checking #bam first,
> won't it only find the <div /> element?
>

The DOM2 has this to say:

getElementById introduced in DOM Level 2
>     Returns the Element whose ID is given by elementId. If no such
> element exists, returns null. Behavior is not defined if more than one
> element has this ID.
>

Source: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-getElBId

I would think that the first one the browser finds is selected, but I
can't be certain of that as I've never actually tried to do this.

--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com

Reply via email to