W3C home > Mailing lists > Public > whatwg@whatwg.org > October 2013

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

From: Ian Hickson <ian@hixie.ch>
Date: Thu, 10 Oct 2013 18:41:46 +0000 (UTC)
To: Glenn Maynard <glenn@zewt.org>
Message-ID: <alpine.DEB.2.00.1310101838190.11763@ps20323.dreamhostps.com>
Cc: whatwg <whatwg@lists.whatwg.org>, Boris Zbarsky <bzbarsky@mit.edu>
On Wed, 9 Oct 2013, Glenn Maynard wrote:
> On Wed, Oct 9, 2013 at 7:02 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> > On 6/28/13 10:01 PM, Boris Zbarsky wrote:
> >> On 6/28/13 5:06 PM, Tab Atkins Jr. wrote:
> >>
> >>> getElementById("foo") is just querySelector("#foo")
> >>
> >> This is actually false.  For example, getElementById("foo:bar") is 
> >> just querySelector("#foo\\:bar"), which is ... nonobvious.
> >
> > And today someone asked me how to do the equivalent of 
> > getElementById("\n") with querySelector.  That one is even more 
> > non-obvious.
> 
> But it's already been suggested--by you--that we need a function to 
> CSS-escape a string, which seems to solve the that problem trivially 
> (for users).

Leaving aside the issue that "CSS-escape" is more than one operation 
depending on what kind of token you're creating, I don't think it's 
actually as trivial as you think.

   document.getElementById(id)

...becomes:

   document.querySelector('#' + escapeCSSIdent(id))

...which is a lot less pretty and understandable, especially when you 
consider that many authors are actually coming from:

   document.all[id]

...which is briefer than either, and still self-explanatory.


I feel this is a case where we're not putting authors first, but are 
instead putting spec purity first.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Thursday, 10 October 2013 18:42:10 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:24 UTC