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

Glenn Maynard glenn at zewt.org
Wed Oct 9 17:40:30 PDT 2013


On Wed, Oct 9, 2013 at 7:02 PM, Boris Zbarsky <bzbarsky at 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



More information about the whatwg mailing list