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

Boris Zbarsky bzbarsky at MIT.EDU
Fri Nov 1 18:59:42 PDT 2013


On 10/31/13 7:42 AM, Anne van Kesteren wrote:
> On Wed, Oct 23, 2013 at 4:47 AM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
>> On 10/22/13 7:00 AM, Anne van Kesteren wrote:
>>> So do you think we should add getElementById() to ParentNode in DOM?
>>
>> I actually do, yes.
>
> http://dom.spec.whatwg.org/#parentnode

We can't have nice things.  :(

When I tried to check this in, our automated tests failed while running 
the regression tests for jQuery 1.2.6.  This library has code like so:

   var elem = ret[ret.length-1];
   // Try to do a global search by ID, where we can
   if ( m[1] == "#" && elem && elem.getElementById && 
!jQuery.isXMLDoc(elem) ) {
     // Optimization for HTML document case
     var oid = elem.getElementById(m[2]);
     // etc
   } else {
     // walk the kids of elem
   }

so if you have this markup:

   <div><span id="x"></span></div>
   <div></div>
   <script>
     alert($("div #x").length);
   </script>

you end up with "ret" being the list of divs in the code above.  Then if 
the last div has a getElementById function that gets called and in this 
case returns null, so 0 is alerted.  If it doesn't, then it walks the 
kids and finds the span, so 1 is alerted.

I can obviously adjust our in-tree tests, but this test was part of 
jQuery's regression test suite, and I would be slightly surprised if 
there's no one out there using jQuery 1.2.6 (or later, up until the code 
went away; I did check that jQuery 1.10.2 no longer has the code cited 
above) and if they don't run into this issue.  :(

Anyone think otherwise?

-Boris


More information about the whatwg mailing list