A
A
Alexander Korotaev2010-10-20 12:15:11
JavaScript
Alexander Korotaev, 2010-10-20 12:15:11

Where can I find the getElementById working standard?

In general, the question is simple. Why, when adding 2 elements with the same id to a document, is the first element taken, and not the second?
PS I understand that you have to tear off your hands for this, but still ...

<font color="black"><font color="#0000ff">&lt;</font><font color="#800000">html</font><font color="#0000ff">&gt;</font><br/>
<font color="#0000ff">&lt;</font><font color="#800000">head</font><font color="#0000ff">&gt;</font><br/>
    <font color="#0000ff">&lt;</font><font color="#800000">title</font><font color="#0000ff">&gt;&lt;/</font><font color="#800000">title</font><font color="#0000ff">&gt;</font><br/>
    <font color="#0000ff">&lt;</font><font color="#800000">script</font> <font color="#ff0000">type</font><font color="#0000ff">=&quot;text/javascript&quot;</font><font color="#0000ff">&gt;</font><br/>
        <font color="#0000ff">function</font> ondivclick() {<br/>
            <font color="#0000ff">document</font>.getElementById(<font color="#A31515">&quot;place&quot;</font>).innerHTML += <font color="#A31515">&quot;1&quot;</font>;<br/>
            <font color="#0000ff">document</font>.getElementById(<font color="#A31515">&quot;place&quot;</font>).innerHTML += <font color="#A31515">&quot;2&quot;</font>;<br/>
            alert(<font color="#0000ff">document</font>.getElementById(<font color="#A31515">&quot;divid&quot;</font>).innerHTML); <font color="#008000">// тут на всех браузерах будет 1</font><br/>
        }<br/>
    <font color="#0000ff">&lt;/</font><font color="#800000">script</font><font color="#0000ff">&gt;</font><br/>
<font color="#0000ff">&lt;/</font><font color="#800000">head</font><font color="#0000ff">&gt;</font><br/>
<font color="#0000ff">&lt;</font><font color="#800000">body</font><font color="#0000ff">&gt;</font>        <br/>
    <font color="#0000ff">&lt;</font><font color="#800000">a</font> <font color="#ff0000">href</font><font color="#0000ff">=&quot;#&quot;</font> <font color="#ff0000">onclick</font><font color="#0000ff">=&quot;ondivclick()&quot;</font><font color="#0000ff">&gt;</font>Go!<font color="#0000ff">&lt;/</font><font color="#800000">a</font><font color="#0000ff">&gt;</font><br/>
    <font color="#0000ff">&lt;</font><font color="#800000">div</font> <font color="#ff0000">id</font><font color="#0000ff">=&quot;place&quot;</font><font color="#0000ff">&gt;&lt;/</font><font color="#800000">div</font><font color="#0000ff">&gt;</font><br/>
<font color="#0000ff">&lt;/</font><font color="#800000">body</font><font color="#0000ff">&gt;</font><br/>
<font color="#0000ff">&lt;/</font><font color="#800000">html</font><font color="#0000ff">&gt;</font></font><br/>
<br/>
<font color="gray">* This source code was highlighted with <a href="http://virtser.net/blog/post/source-code-highlighter.aspx"><font color="gray">Source Code Highlighter</font></a>.</font>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Matrozov, 2010-10-20
@Mear

It is logical to assume that due to the fact that it is assumed that all ids in the document are unique, then when searching by id, finding it, the search stops. It makes sense to sort through the elements further if, according to the standard of the second, this cannot be.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question