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

Boris Zbarsky bzbarsky at MIT.EDU
Thu Sep 5 18:50:33 PDT 2013


On 9/5/13 6:02 AM, Anne van Kesteren wrote:
> Having said that, our current plan is to rely on the Selectors API (2)

In that case I think we need to add a function to the platform that 
CSS-escapes a string.  Because right now, writing

   querySelector("#" + id)

is a total footgun unless you control the id.  In particular, if you're 
a library you're in trouble...

> but the hope is that .querySelector("#test") will be fast
> enough.

As I explained in the thread, they have quite different behavior: 
getElementById takes the ID, but querySelector needs a CSS-escaped form 
of the ID.

I'm happy to raise this point on www-dom if you want.  Just let me know.

-Boris



More information about the whatwg mailing list