Note that there are some explanatory texts on larger screens.

plurals
  1. POUnpredicted behavior of using non-unique IDs
    primarykey
    data
    text
    <p>When people are saying that using identical id's for different DOM elements is wrong, I totally agree. I mean, there is no even something to discuss.</p> <p>But what is actually meant by the phrase "if you will have several eponymous ids on the page, that doesn't guaranteed to work"? </p> <p>What actually does not guaranteed to work? We can treat ID as a regular attribute, thus, we can find all divs that <code>document.querySelectorAll('[id="container"]')</code>. Accessing through getAttribute/setAttribute should work as well. If we are trying to fetch an element via <code>document.getElementById</code> - well, I haven't tested, but most probably selector engine will return first element it find traversing the tree. I can imagine this can not be guaranteed. What else?</p> <p>CSS will work pretty fine - <code>#container {background-color: "red"}</code> will paint with red all found containers (or am I wrong). Can somebody show me where in standard spec such behaviour is not guaranteed? </p> <p>So, what is actually not guaranteed? Once again, I do acknowledge the fact that using same IDs is wrong. Neither do I want discuss perfomance issues of applying id-heavy css rules. The question is about something which is quite similar to what C/C++ programmers call "unpredicted behavior".</p> <p><strong>UPD:</strong> If it sounds hard or even stupid for you, then well, just provide an examples of unpredictable ID related behavior in specific browser. At least, as for me, it is more useful answer than "well, anything is not guaranteed, how can not you get it!".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload