- From: Jussi Kalliokoski <jussi.kalliokoski@gmail.com>
- Date: Sun, 30 Jun 2013 22:44:26 +0300
- To: Boris Zbarsky <bzbarsky@mit.edu>
- Cc: whatwg@lists.whatwg.org
On Sat, Jun 29, 2013 at 5:01 AM, Boris Zbarsky <bzbarsky@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
Received on Sunday, 30 June 2013 19:44:50 UTC