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

Octavian Damiean odamiean at linux.com
Sun Jun 30 23:56:52 PDT 2013


On Sun, Jun 30, 2013 at 9:44 PM,
​​
Jussi Kalliokoski <jussi.kalliokoski at gmail.com> wrote:

> On Sat, Jun 29, 2013 at 5:01 AM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
>
> > This is actually false.  For example, getElementById("foo:bar") is just
> > querySelector("#foo\\:bar"), which is ... nonobvious.
> >
> > It gets worse if you don't control the id that's passed in, because
> > getElementById(arg) becomes querySelector("#"+cssEscape(arg)) where
> > cssEscape is a not entirely trivial-to-write function, if you want it to
> > work reliably.
>
>
> Not only is it not completely obvious how these methods are interoperable,
> but also the readability of code involving querySelector is questionable:
>
> this.buttonElement = document.querySelector('#' + this.buttonId);
> this.buttonElement = document.getElementById(this.buttonId);
>
> Not to mention that if you have to perform transformations on the variable,
> such as .replace(/:/g, '//:'), in a lot of cases using querySelectors is
> just way less clear a way of expressing the intention than the "obsolete"
> methods that say perfectly well what you want. Query selectors are a very
> powerful tool for complicated queries, but a lot of the time you don't need
> that power and at least in those cases I'd prefer using a more expressive
> way. The getElement methods aren't going away (and I think that's a good
> thing) and I believe it's a good idea we be consistent here and make
> DocumentFragments have these methods as well. Use the right tool for the
> job.
>
> Cheers,
> Jussi
>

​I completely agree with ​Jussi here. It's also not really constructive to
argue whether querySelector is more powerful not, we're talking about
consistency.

​Cheers,​
-- 
Octavian Damiean

GitHub: https://github.com/mainerror



More information about the whatwg mailing list