This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23860 - Remove getElementById() from Element
Summary: Remove getElementById() from Element
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-19 17:21 UTC by Anne
Modified: 2013-11-28 21:28 UTC (History)
7 users (show)

See Also:


Attachments

Description Anne 2013-11-19 17:21:00 UTC
jQuery made it web-incompatible. We can only have it on Document and DocumentFragment.

If there's potential other things we only want there we might want to introduce NonElementParentNode as group.
Comment 1 Boris Zbarsky 2013-11-19 17:27:37 UTC
Document, DocumentFragment, and SVGSVGElement, fwiw.
Comment 2 Anne 2013-11-19 17:30:26 UTC
Right. I should ping www-svg@w3.org to get them to point to our definition.
Comment 3 Marat Tanalin | tanalin.com 2013-11-19 21:39:16 UTC
(In reply to Anne from comment #0)
> jQuery made it web-incompatible.

Could you share some details? Thanks.
Comment 4 Boris Zbarsky 2013-11-19 21:41:32 UTC
jQuery 1.2.5 assumes that any node it found in the DOM that has a "getElementById" property is a Document node.  See https://bugzilla.mozilla.org/show_bug.cgi?id=933193#c17
Comment 5 Boris Zbarsky 2013-11-19 21:42:14 UTC
Er, I meant jQuery 1.2.6, but 1.2.5 in fact has the same code.
Comment 6 Rick Waldron 2013-11-20 22:24:38 UTC
Can someone point me to the relevant discussions that lead to the addition of "getElementById" to Element, thanks!
Comment 7 Boris Zbarsky 2013-11-20 22:42:33 UTC
Probably starting at http://lists.w3.org/Archives/Public/public-whatwg-archive/2013Jun/0207.html and then going on approximately forever.
Comment 8 Rick Waldron 2013-11-21 01:00:20 UTC
This is unfortunate. If it were an issue with a modern version of the library, I'd personally commit to resolving it, but unfortunately a version from 5 years ago requires a time machine and mine is in the shop. 

@mozillians: Is there any way to gather info on jQuery version use in Firefox? I'm willing to do evangelism, on behalf of jQuery, for any major site breakage this change may cause—if there is a way to identify breakage? Can the change be made temporarily? In a Nightly?
Comment 9 Rick Waldron 2013-11-21 01:05:18 UTC
I have no idea how realistic this is, but if you asked me to guess, this is pretty close to what I would say the usage is http://w3techs.com/technologies/details/js-jquery/1/all
Comment 10 Boris Zbarsky 2013-11-21 03:30:45 UTC
> @mozillians: Is there any way to gather info on jQuery version use in Firefox?

We can try, but the version is often in neither the url nor the actual script...

Also worth asking the Blink folks if they can do this.

> for any major site breakage this change may cause—if there is a way to identify
> breakage?

That's the problem.  The symptom is that some queries will just return the wrong nodeset.  What happens after that depends on what the site is doing.  And no breakage today is no guarantee of anything tomorrow.  :(

> Can the change be made temporarily? In a Nightly?

We could try; we'd have to disable our jQuery regression tests or something, since those also break with the change (which is how the problem was discovered).  That has its own problems, obviously.
Comment 11 Rick Waldron 2013-11-21 19:24:47 UTC
(In reply to Boris Zbarsky from comment #10)
> > @mozillians: Is there any way to gather info on jQuery version use in Firefox?
> 
> We can try, but the version is often in neither the url nor the actual
> script...
> 

jQuery.fn.jQuery is where the version is always exposed, since 1.3 (if it's not present, then "mostly" safe to assume it's pre-1.3)

> Also worth asking the Blink folks if they can do this.

Agreed! 

> 
> > for any major site breakage this change may cause—if there is a way to identify
> > breakage?
> 
> That's the problem.  The symptom is that some queries will just return the
> wrong nodeset.  What happens after that depends on what the site is doing. 
> And no breakage today is no guarantee of anything tomorrow.  :(
> 
> > Can the change be made temporarily? In a Nightly?
> 
> We could try; we'd have to disable our jQuery regression tests or something,
> since those also break with the change (which is how the problem was
> discovered).  That has its own problems, obviously.

Of course and I will understand if this can't happen at all. I will continue to seeking more information about version usage and will post back here.
Comment 12 Boris Zbarsky 2013-11-21 19:36:49 UTC
> jQuery.fn.jQuery is where the version is always exposed

Mmm...  We could try to look for that, but invoking functions of the page when they don't expect to be like that is pretty dangerous from a compat standpoint (and hence there is real infrastructure for doing it, since we never want to do it).  :(
Comment 13 Rick Waldron 2013-11-21 19:41:38 UTC
It's a property(In reply to Boris Zbarsky from comment #12)
> > jQuery.fn.jQuery is where the version is always exposed
> 
> Mmm...  We could try to look for that, but invoking functions of the page
> when they don't expect to be like that is pretty dangerous from a compat
> standpoint (and hence there is real infrastructure for doing it, since we
> never want to do it).  :(

It's a property :)
Comment 14 Boris Zbarsky 2013-11-21 20:04:12 UTC
A property get is in general a function call, though.  We don't have a sane way from the non-js-engine part of gecko to do "get this property, but only if it's a value property and if you can determine that without running any script (e.g. none of the objects are proxies)"...  We could try to add a bunch of complex code to do that, I guess...
Comment 15 Marat Tanalin | tanalin.com 2013-11-21 20:15:24 UTC
A couple of ideas about how jQuery could be precisely identified:

1. compare checksums (predefined in browser) of official JS files distributed via jQuery website with checksums of files which URL (or filename) contains "jquery" string (most likely jQuery file is typically used as is -- without modifications);

2. take URLs of jQuery hosted on popular CDN's (e.g. Google's) into account.
Comment 16 Rick Waldron 2013-11-21 20:23:56 UTC
(In reply to Marat Tanalin | tanalin.com from comment #15)
> A couple of ideas about how jQuery could be precisely identified:
> 
> 1. compare checksums (predefined in browser) of official JS files
> distributed via jQuery website with checksums of files which URL (or
> filename) contains "jquery" string (most likely jQuery file is typically
> used as is -- without modifications);

For statically scanning the official release of jQuery:

- the minified version string looks like: `f="1.10.2"`
- the source version string looks like: `core_version = "1.10.2"`

But this may appear differently in older versions of jQuery. 

The header of jquery.js and jquery.min.js also include version:

"v1.10.2"

This pattern (ie. "v1.x[.x]" has been the same since jQuery 1.3

> 
> 2. take URLs of jQuery hosted on popular CDN's (e.g. Google's) into account.

Yep, this was #1 on my list to check into :)
Comment 17 Erik Arvidsson 2013-11-21 21:11:40 UTC
Why was getElementById added to ParentNode in the first place?
Comment 18 Boris Zbarsky 2013-11-21 22:47:20 UTC
Erik, see comment 7.
Comment 19 Mike Taylor 2013-11-22 16:06:46 UTC
I asked Corey of the jQuery infrastructure team to pull stats on downloads from their code.jquery.com CDN: https://gist.github.com/gnarf/471375415438802390a9. This data is "this month from one of the cdn hosts".
Comment 21 Rick Waldron 2013-11-26 15:30:44 UTC
(In reply to Anne from comment #20)
> https://github.com/whatwg/dom/commit/f71d7de304e1ee25573279157dd6ce1c2aa2c4f2

Based on the CDN request data the Mike provided above, there were only 6,952 requests for jQuery 1.2.x, out of total 34,201,901 valid requests for jQuery (0.02033%).
Comment 22 Marat Tanalin | tanalin.com 2013-11-26 20:20:40 UTC
By the way, on syntax level, we could just add context element as optional second parameter to existing `document.getElementById()` method so that

    document.getElementById('example', someElement)

would be equivalent to

    someElement.getElementById('example')

Same is probably applicable to DocumentFragment.
Comment 23 Anne 2013-11-28 14:10:02 UTC
Rick, if you can get Chrome to implement it on Element, or manage to change bz' mind for Firefox, I will update the specification. For now I'm happy with moving forward with just adding it to DocumentFragment (and therefore ShadowRoot).
Comment 24 Erik Arvidsson 2013-11-28 15:24:06 UTC
I still don't get it. Why do we want getElementById on Element?
Comment 25 Boris Zbarsky 2013-11-28 15:29:42 UTC
Erik, did you read the mailing list discussion about that exact question?
Comment 26 Erik Arvidsson 2013-11-28 21:28:21 UTC
(In reply to Boris Zbarsky from comment #25)
> Erik, did you read the mailing list discussion about that exact question?

Yes. I didn't find a conclusion to that thread and the arguments were not very convincing. Anyway, please feel free to ignore me.