What is the difference between a HTMLCollection and a NodeList in DOM? [duplicate]
Asked Answered
S

1

12

I tried my Google-fu but I can't seem to find any good answer to that question. Please help.

EDIT: Ok so I found this blog post. So they come from different DOM levels, but besides that it doesn't say much...

Stickseed answered 26/3, 2013 at 0:38 Comment(0)
M
8

As you said, NodeList is defined in DOM-Level-3-Core and HTMLCollection in DOM-Level-2-HTML.

Their interfaces are :

interface HTMLCollection {
  readonly attribute unsigned long   length;
  Node               item(in unsigned long index);
  Node               namedItem(in DOMString name);
};

interface NodeList {
  Node               item(in unsigned long index);
  readonly attribute unsigned long   length;
};

So NodeList is a successor of HTMLCollection in a more generic form (for xml).

Methodize answered 30/4, 2013 at 18:2 Comment(2)
w3.org/TR/DOM-Level-2-HTML/html.html#ID-75708506 and w3.org/TR/DOM-Level-3-Core/core.html#ID-536297177Methodize
this has gotta be the LEAST helpful answer on our planet Earth. Can we ever get a simple, explain-it-like-im-five answer? Ever? I always see links to outgoing articles filled with jargon or copypastas of the literal interface/class definitions. How is that in any way helpful??Metastasize

© 2022 - 2024 — McMap. All rights reserved.