- From: Jonas Sicking <jonas@sicking.cc>
- Date: Wed, 3 Dec 2008 11:39:09 -0800
> Otherwise, just let the id attribute be unique in the whole document, label > any duplicate one as illegal and treat it as the empty string, so that one > only method is enough and the DOM 3 undefined behaviour for 'getElementById' > is no more problematic, being fired by non-allowed DOM structures (as don't > care conditions). Such would be the easiest choice, although there might be > any good reason to prefer allowing replicated ids inside the same document. Note that having multiple IDs is quite common on real-world pages. Especially ones that actively modify the DOM since often subtrees containing nodes with IDs are cloned and reinserted. So if we do this I expect quite a few pages to break. In firefox we now always return the first element with the requested ID. I think IE does the same. This seems equally reliably and much less likely to cause page breakage or interoperability issues. As for CSS, I believe in firefox we make all elements with a given ID match the #foo selector. I don't have a strong feeling if this is the correct thing to do, or just make the first one match. The only concern I have is performance. / Jonas
Received on Wednesday, 3 December 2008 11:39:09 UTC