4

As I know,getElementsByName is a function defined in HTMLDocument,and HTMLDocument inherits from Document,and Document inherits from Node.

So why I can see Document.prototype.getElementsByName in Chrome but not Firefox?Does not Chrome implement DOM2 spec?

Shiva
  • 6,677
  • 4
  • 36
  • 61
yanni4night
  • 137
  • 7
  • Why would it be *wrong* to provide it even on `Document`? They *do* follow the spec, as it is available on `HTMLDocument`. – Bergi Feb 14 '14 at 05:56
  • Link to the spec is here: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-71555259 – Johannes H. Feb 14 '14 at 05:56
  • 2
    [This discussion](http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-August/032878.html), though dated, seems to be related. – Ja͢ck Feb 14 '14 at 06:21

1 Answers1

3

Does not Chrome implement DOM2 spec?

Yeah, probably not. I'd guess they at least implement DOM 3, if not a more current version :-)

However, those don't define a getElementsByName either. So how did they get this? It is actually specified in HTML5 (WHATWG/W3) on the Document partial interface:

The DOM specification defines a Document interface, which this [HTML5] specification extends significantly […]

And at http://dev.w3.org/html5/spec-LC/dom.html#documents-in-the-dom I found the note

Because the HTMLDocument interface is now obtained using binding-specific casting methods instead of simply being the primary interface of the document object, it is no longer defined as inheriting from Document.

So the specification details of these interfaces are still in progress, and varying. Notice that browsers are not even supposed to export any kind of DocumentPrototype - the specs do only define interfaces, not the exact EcmaScript binding representation of them. WebIDL does.

So Chrome does follow the newer specs (but still has some HTMLDocument?), while Firefox implements an older version. However, it only really matters that these methods do exist on every window.document - not how they got there :-)

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • And what the relation between w3c.org and whatwg.org on HTML spec?Which should I read?Little confuse – yanni4night Feb 28 '14 at 02:32
  • [*The politics are ugly*](http://stackoverflow.com/questions/6825713/html5-w3c-vs-whatwg-which-gives-the-most-authoritative-spec). Actually, there shouldn't be much difference, [but nobody knows](http://www.whatwg.org/specs/web-apps/current-work/multipage/introduction.html#is-this-html5?). – Bergi Feb 28 '14 at 16:37