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

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

From: Glenn Maynard <glenn@zewt.org>
Date: Wed, 9 Oct 2013 19:40:30 -0500
Message-ID: <CABirCh-pa5rehx8d1=Z6xKQaSBUHGMJMj+b6ug4YhcMBEN-yXw@mail.gmail.com>
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: whatwg <whatwg@lists.whatwg.org>
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).

I often do things like saving an element's elem.dataset.someId, and then
finding the element again later by saying
container.querySelector('[data-some-id="' + saved_id + '"]'.  (That lets me
find the element later, even if it's been replaced by a new element, which
doesn't work if I just save a reference.)  That would help there, too,
since I wouldn't need to make sure that my IDs don't need to be escaped.

-- 
Glenn Maynard
Received on Thursday, 10 October 2013 00:40:53 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:11 UTC