What is the difference between a HTMLCollection and a NodeList in DOM?

╄→гoц情女王★ 提交于 2019-12-08 15:09:38

问题


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...


回答1:


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).



来源:https://stackoverflow.com/questions/15627385/what-is-the-difference-between-a-htmlcollection-and-a-nodelist-in-dom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!