What is the difference of NodeList for HTMLCollection?

3

I was reading a code when I came across the following question, would you like to know if anyone could enlighten me?

    
asked by anonymous 27.05.2014 / 13:14

1 answer

3

Both interfaces are collections of nodes DOM . They differ in the methods they provide and in the type of nodes they can contain. While a NodeList can contain any type of node , a HTMLCollection should contain only element nodes ( HTM / XML ).

A HTMLCollection provides the same methods as a NodeList and, additionally, a method called NamedItem() , which retrieves a node using a name. In HTML documents, it first looks for a node with a corresponding id attribute, if it does not find one then looks for a node with an name attribute attribute, but only on those elements that are allowed an name attribute.

In XHTML documents, this method only searches for nodes with a corresponding id attribute. It is worth remembering that this method is case insensitive in HTML and case sensitive documents in XHTML documents. >

References:

27.05.2014 / 13:52