[whatwg] Use cases for Node.getElementById (was: Re: Early feedback on header association algorithm)
joao.eiras at gmail.com
Sun Dec 7 06:41:06 PST 2008
IMO, anyone suggesting a Node.getElementById clearly does not know very
well how getElementById is supposed to work.
There are ways to transverse a DOM tree currently, either DOM properties
and methods, XPath, selectors API and such.
Considering ids are required to be unique in the context of a single
document, implementations can, and do, implement id lookup using optimized
data structures like a hash table, which is much more performant than
So if there is a special node in a document, add an id to it and get its
reference will be performant (ideally O(1)).
If the uniqueness requirement is removed, then getElementById looses its
whole meaning and should actually be removed from the specification
entirely, else then we would need more bloat like getElementById or
getElementListById and whatever.
If you really need to get the element with id in a subtree, connected or
disconnected from the main tree, one can use selectors API, DOM
transversal, XPath, etc.
So, IMO the DOM spec is just fine. What is asked for Node.getElementById
is already supported by other APIs.
More information about the whatwg