It depends on the browser, but most likely uses the hash map from id-> element. It is true that there are many invalid pages with duplicate identifiers. However, the browser will still return only one item, not a collection.
I do not know what you mean by "next to the elements", since the method exists only on document.
, , Firefox Chrome.