What’s the difference between Nodelist and Htmlcollection?

Asked

Viewed 291 times

4

I was reading a code when I came across the following question, I was wondering if anyone could enlighten me?

1 answer

6


Both interfaces are collections of nodes DOM. They differ in the methods they provide and the type of nodes they can contain. As a NodeList may contain any kind of knot, one HTMLCollection shall contain only element knots(HTM/XML).

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

In documents XHTML, this method only looks for us with an attribute id correspondent. It is worth remembering that this method is case insensitive, in documents HTML and case sensitive in documents XHTML.

References:

  • 1

    Another notable difference is that Htmlcollection is always live, while Nodelists can be live or not (according to MDN, at least).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.