Re: [whatwg] Proposal: Adding methods like getElementById and getElementsByTagName to DocumentFragments

On Oct 22, 2013, at 4:00 AM, Anne van Kesteren <annevk@annevk.nl> wrote:

> On Fri, Oct 18, 2013 at 10:56 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
>> So it looks to me like in practice Element.getElementById could be quite a
>> bit faster than the equivalent querySelector call, for both the in-tree case
>> (where both can avoid walking the tree) and the out-of-tree case (where both
>> need to walk the tree).
>> 
>> Food for thought.
> 
> So do you think we should add getElementById() to ParentNode in DOM?

Why not to Element?

> It seems the advantages are that we can optimize it better than
> querySelector() because there is no selector parsing. And because
> there is no selector parsing, you can simply pass the value of an
> element's id attribute rather than escaping said value using CSS
> escape rules.
> 
> What it seems we lack is a clear need for either, but if the cost of
> implementing it is low, maybe it's worth it?

Because of HTMLCollection's name getter, all major browsers must be capable of a id+name lookup at every element (since Element has getElementsByTagName that returns a HTMLCollection).

- R. Niwa

Received on Tuesday, 22 October 2013 18:43:22 UTC